Documentation
¶
Overview ¶
Package magic is a wrapper around file's libmagic.
Index ¶
- Constants
- Variables
- func Version() string
- func VersionInt() int
- type Magic
- func (m *Magic) Buffer(buf []byte) (string, error)
- func (m *Magic) BufferTypes(buf []byte, flags ...int) ([]string, error)
- func (m *Magic) BufferWith(flags int, buf []byte) (string, error)
- func (m *Magic) Close() error
- func (m *Magic) File(name string) (string, error)
- func (m *Magic) FileTypes(name string, flags ...int) ([]string, error)
- func (m *Magic) FileWith(flags int, name string) (string, error)
- func (m *Magic) Flags() int
- func (m *Magic) SetFlags(flags int) error
Constants ¶
const ( None = C.MAGIC_NONE Debug = C.MAGIC_DEBUG Symlink = C.MAGIC_SYMLINK Compress = C.MAGIC_COMPRESS Devices = C.MAGIC_DEVICES MimeType = C.MAGIC_MIME_TYPE MimeEncoding = C.MAGIC_MIME_ENCODING Mime = C.MAGIC_MIME Continue = C.MAGIC_CONTINUE Check = C.MAGIC_CHECK PreserveATime = C.MAGIC_PRESERVE_ATIME Raw = C.MAGIC_RAW Error = C.MAGIC_ERROR Extension = C.MAGIC_EXTENSION )
Magic flags. Mirrors MAGIC_* constants in magic.h.
Variables ¶
var MagicDB []byte
MagicDB is the compiled magic database. It is byte-identical for every target -- the format is endian-independent and libmagic byte-swaps on load -- so one embedded copy serves all platforms.
Functions ¶
Types ¶
type Magic ¶
type Magic struct {
// contains filtered or unexported fields
}
Magic is an open libmagic handle with the embedded database loaded.
A magic_t cookie holds mutable per-lookup state and is not safe for concurrent use, so every method below serializes on mu. That makes a single Magic safe to share across goroutines, at the cost of serializing lookups: for parallel throughput, give each worker its own handle.
func (*Magic) BufferTypes ¶
BufferTypes identifies the contents of buf once per entry in flags, returning a result for each. Passing no flags uses the handle's own.
The whole sequence runs under a single lock, so the results describe the same buffer through the same handle with no other goroutine interleaving:
desc, err := m.BufferTypes(buf, magic.None, magic.MimeType, magic.Extension)
func (*Magic) BufferWith ¶
BufferWith identifies the contents of buf using flags, leaving the handle's configured flags unchanged.
func (*Magic) Close ¶
Close releases the handle and the database copy. It is safe to call twice, and safe to race with other methods: they report a closed handle rather than touching a freed cookie.
func (*Magic) FileTypes ¶
FileTypes identifies the file at name once per entry in flags, returning a result for each. Passing no flags uses the handle's own.
The whole sequence runs under a single lock, so the results describe the same file through the same handle with no other goroutine interleaving:
desc, err := m.FileTypes("x.png", magic.None, magic.MimeType, magic.Extension)
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
file
command
|
|
|
compress
|
|
|
xz
module
|
|
|
zstd
module
|
|
|
libmagic
|
|
|
darwin_amd64
module
|
|
|
darwin_arm64
module
|
|
|
freebsd_amd64
module
|
|
|
linux_amd64
module
|
|
|
linux_arm
module
|
|
|
linux_arm64
module
|
|
|
windows_amd64
module
|
|
|
windows_arm64
module
|