https://github.com/velocidex/go-magic
Go bindings for libmagic
https://github.com/velocidex/go-magic
Last synced: 2 months ago
JSON representation
Go bindings for libmagic
- Host: GitHub
- URL: https://github.com/velocidex/go-magic
- Owner: Velocidex
- License: apache-2.0
- Created: 2021-10-18T07:53:19.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-02-03T09:40:20.000Z (4 months ago)
- Last Synced: 2025-04-14T16:01:42.154Z (2 months ago)
- Language: C
- Size: 671 KB
- Stars: 7
- Watchers: 2
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-magic #
## Go bindings for libmagic ##
There are number of existing bindings for libmagic, for example
`github.com/vimeo/go-magic`.This binding aims to be self contained, without requiring libmagic to
be installed. This allows us to build this dependency for all
architectures even Windows.### Installing ###
```
go get https://github.com/Velocidex/go-magic
```This package contains libmagic source code already so you do not need
to have it installed on the system.### How to use it from Go code.
The first step is to obtain a handle to the library.
```go
handle := magic.NewMagicHandle(magic.MAGIC_NONE)
defer handle.Close()// Load built in magic files
magic_files.LoadDefaultMagic(handle)
classification := handle.File("foobar.jpeg")
```This binding bundles the built in magic files. You can load them into
memory by calling `magic_files.LoadDefaultMagic(handle)`.The packages magic files are the default ones provided by the file
package.## Reference
* File source code is here https://github.com/file/file