Get MIME type of a file with libmagic
| src | [dev] Initial Implementation of getMIME | |
| .clang-format | [style] Added .clang-format | |
| .gitignore | [dev] Hello World | |
| build.zig | [dev] Initial Implementation of getMIME | |
| build.zig.zon | [build] Version bump | |
| LICENSE | [LICENSE] MIT | |
| README.md | [docs] Update URL | |
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
constzmime_dep=b.dependency("libzmime",.{.target=target,.optimize=optimize,});Usage
conststd=@import("std");constzmime=@import("zmime");pubfnmain(init:std.process.Init)!void{constio=init.io;// we are writing to stdout in this examplevarstdout_buf:[1024]u8=undefined;varstdout_writer=std.Io.File.stdout().writer(io,&stdout_buf);constsw=&stdout_writer.interface;tryzmime.getMIME(sw,"filename");trysw.writeByte('\n');trysw.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