A simple wrapper around libmagic and exposes a single function getMIME, which gives the MIME Type of a file.
I hate it, but here are the dependencies that you need
- Debian/Ubuntu
apt install libmagic-devTo use this library in your project just do
Min Zig Version 0.16.0
zig fetch --save git+https://codeberg.org/Adwaith-Rajesh/libzmime.git
const zmime_dep = b.dependency("libzmime", .{
.target = target,
.optimize = optimize,
});const std = @import("std");
const zmime = @import("zmime");
pub fn main(init: std.process.Init) !void {
const io = init.io;
// we are writing to stdout in this example
var stdout_buf: [1024]u8 = undefined;
var stdout_writer = std.Io.File.stdout().writer(io, &stdout_buf);
const sw = &stdout_writer.interface;
try zmime.getMIME(sw, "filename");
try sw.writeByte('\n');
try sw.flush();
}Output
If the file is a plain text file
text/plainIf you have any issue, please create an issue in the Issue Tracker or join the Discord Server