Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lun-4/libmagic.zig
static build of libmagic
https://github.com/lun-4/libmagic.zig
Last synced: about 2 months ago
JSON representation
static build of libmagic
- Host: GitHub
- URL: https://github.com/lun-4/libmagic.zig
- Owner: lun-4
- License: mit
- Created: 2022-11-05T02:14:21.000Z (about 2 years ago)
- Default Branch: mistress
- Last Pushed: 2024-08-07T02:47:08.000Z (6 months ago)
- Last Synced: 2024-12-01T10:54:17.917Z (about 2 months ago)
- Language: Zig
- Size: 548 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# libmagic.zig
## problem statement
libmagic is a cool library, however the path to the default magic database file
can be configured as a build option.you'd need to create some form of heuristic to find out the system magic file
and hope it works.this fucks up any attempt at statically linking libmagic
this library came out of this pain, and the want to not depend on any system
libraries. it's hacky, but it works.tested on
- `x86_64-linux-gnu`
- `x86_64-macos-none`## WARNING
this library contains a 7MB binary blob that is the libmagic database. the
library will write the 7MB blob to a file in your filesystem and reuse it when
possible.to prevent writing and reading from that file all the time, the heuristics are
still loaded for the system magic file, and if they work, they will be used (
this behavior is overridable by the `loading_mode` in `MimeCookie.init`).## usage
zigmod supported for now. add the following:
```yaml
- src: git https://github.com/lun-4/libmagic.zig
``````zig
const MimeCookie = @import("libmagic.zig").MimeCookie;// then
var cookie = try MimeCookie.init(allocator, .{}),
defer cookie.deinit();
const mimetype = try self.cookie.inferFile("path/to/my/file/as/a/null/terminated/string");
```