Skip to content

Adwaith-Rajesh/libzmime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LibZMIME


A simple wrapper around libmagic and exposes a single function getMIME, which gives the MIME Type of a file.

As with all projects, new features will be added when I need them :)

Dependencies

I hate it, but here are the dependencies that you need

  • Debian/Ubuntu
apt install libmagic-dev

Installing

To use this library in your project just do

Min Zig Version 0.16.0

Getting LibZMIME

zig fetch --save git+https://codeberg.org/Adwaith-Rajesh/libzmime.git

Build.Zig

const zmime_dep = b.dependency("libzmime", .{
    .target = target,
    .optimize = optimize,
});

Usage

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/plain

If you have any issue, please create an issue in the Issue Tracker or join the Discord Server

Byeee...

About

[MIRROR] Get MIME type of a file with libmagic

Topics

Resources

License

Stars

Watchers

Forks

Contributors