MegaMimes

MegaMimes v2.1

Tiny, dependency-free C99 library for MIME detection and content classification.

MegaMimes probes files with layered evidence:

It also reports text/binary classification and text encoding.

What’s New in 2.1

Core Features

Build (shared lib + CLI)

rm -rf build
cmake -S . -B build -DMEGA_BUILD_SHARED=ON -DMEGA_BUILD_CLI=ON -DMEGA_ENABLE_TESTS=ON
cmake --build build -j

Run Tests

ctest --test-dir build --output-on-failure -V

Install (optional)

cmake --install build --prefix /usr/local
pkg-config --cflags --libs megamimes

CLI Usage

# Analyze a file
./build/mmime /path/to/file

# JSON output
./build/mmime /path/to/file --json

Minimal C API Usage

#include "megamimes.h"
#include <stdio.h>

int main(void) {
  MegaMimesCtx* ctx = mega_open(NULL);
  if (!ctx) return 1;

  mega_set_mode(ctx, MEGA_MODE_STRICT);
  mega_set_max_bytes(ctx, 4096);

  MegaFileInfo* info = NULL;
  if (mega_probe_path(ctx, "file.pdf", &info) == MEGA_OK) {
    printf("mime=%s source=%s confidence=%.2f suspicious=%d\n",
      info->mime_type,
      info->source,
      info->confidence,
      info->suspicious);

    for (size_t i = 0; i < info->candidate_count; i++) {
      printf("candidate[%zu] %s (%.2f)\n",
        i,
        info->candidates[i].mime,
        info->candidates[i].confidence);
    }
  }

  mega_free(ctx, info);
  mega_close(ctx);
  return 0;
}

CMake Options

Project Layout

.
|- include/   # public headers
|- src/       # library sources
|- tools/     # mmime CLI
|- tests/     # CTest suites
`- CMakeLists.txt