compile

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: BSD-2-Clause, BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package compile builds a softmagic database from rule source on a file system, as file(1) reads a magic directory, and identifies the result by a SHA-256 of what it read. It is a separate package so that a program which only loads a compiled database, the common case, links neither the hashing nor its package initialiser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(base, extra *softmagic.Database) (*softmagic.Database, error)

Append returns a database that searches base first and then extra, as file(1) searches the directories of `-m a:b`; see Database.Join. Its hash is the SHA-256 of both inputs' hashes.

func Compile

func Compile(fsys fs.FS, o softmagic.CompileOptions) (*softmagic.Database, error)

Compile reads every regular file at the root of fsys, in byte order of name as the reference does, and builds the sorted database. Files whose names begin with a dot are skipped, as are directories and anything else that is not a regular file.

func Dump

func Dump(fsys fs.FS, o softmagic.CompileOptions) (string, error)

Dump is file -c over a rule directory: each rule line, in the order read, in libmagic's parsed form (see softmagic.DumpSources). It reads fsys as Compile does.

func Hash

func Hash(srcs []softmagic.Source) string

Hash is the identity of a rule set: the hex SHA-256 over each source's name, a newline and its text, in order.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL