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.
rm -rf build
cmake -S . -B build -DMEGA_BUILD_SHARED=ON -DMEGA_BUILD_CLI=ON -DMEGA_ENABLE_TESTS=ON
cmake --build build -j
ctest --test-dir build --output-on-failure -V
cmake --install build --prefix /usr/local
pkg-config --cflags --libs megamimes
# Analyze a file
./build/mmime /path/to/file
# JSON output
./build/mmime /path/to/file --json
#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;
}
.
|- include/ # public headers
|- src/ # library sources
|- tools/ # mmime CLI
|- tests/ # CTest suites
`- CMakeLists.txt