Documentation
¶
Overview ¶
Package magic holds the matching functions used to find MIME types.
Index ¶
- func AAC(raw []byte, _ uint32) bool
- func AMp4(raw []byte, _ uint32) bool
- func APK(raw []byte, _ uint32) bool
- func AVIF(raw []byte, _ uint32) bool
- func Aiff(raw []byte, limit uint32) bool
- func Amf(raw []byte, _ uint32) bool
- func Amr(raw []byte, _ uint32) bool
- func Ape(raw []byte, _ uint32) bool
- func Apng(raw []byte, _ uint32) bool
- func Ar(raw []byte, _ uint32) bool
- func Asf(raw []byte, _ uint32) bool
- func Atom(raw []byte, _ uint32) bool
- func Au(raw []byte, _ uint32) bool
- func Avi(raw []byte, limit uint32) bool
- func Bmp(raw []byte, _ uint32) bool
- func Bpg(raw []byte, _ uint32) bool
- func Bz2(raw []byte, _ uint32) bool
- func CBOR(raw []byte, _ uint32) bool
- func CHM(raw []byte, _ uint32) bool
- func CRX(raw []byte, limit uint32) bool
- func CSV(raw []byte, limit uint32) bool
- func Cab(raw []byte, _ uint32) bool
- func Class(raw []byte, limit uint32) bool
- func Collada(raw []byte, _ uint32) bool
- func Cpio(raw []byte, _ uint32) bool
- func DXF(raw []byte, _ uint32) bool
- func Dbf(raw []byte, limit uint32) bool
- func Dcm(raw []byte, limit uint32) bool
- func Deb(raw []byte, _ uint32) bool
- func DjVu(raw []byte, _ uint32) bool
- func Doc(raw []byte, _ uint32) bool
- func Docx(raw []byte, limit uint32) bool
- func Dvb(raw []byte, _ uint32) bool
- func Dwg(raw []byte, _ uint32) bool
- func Elf(raw []byte, _ uint32) bool
- func ElfDump(raw []byte, limit uint32) bool
- func ElfExe(raw []byte, limit uint32) bool
- func ElfLib(raw []byte, limit uint32) bool
- func ElfObj(raw []byte, limit uint32) bool
- func Eot(raw []byte, limit uint32) bool
- func Epub(raw []byte, _ uint32) bool
- func Exe(raw []byte, _ uint32) bool
- func Fdf(raw []byte, _ uint32) bool
- func Fits(raw []byte, _ uint32) bool
- func Flac(raw []byte, _ uint32) bool
- func Flv(raw []byte, _ uint32) bool
- func GLB(raw []byte, _ uint32) bool
- func GLTF(raw []byte, limit uint32) bool
- func Gbr(raw []byte, _ uint32) bool
- func GeoJSON(raw []byte, limit uint32) bool
- func Gif(raw []byte, _ uint32) bool
- func Gml(raw []byte, _ uint32) bool
- func Gpx(raw []byte, _ uint32) bool
- func Gzip(raw []byte, _ uint32) bool
- func HAR(raw []byte, limit uint32) bool
- func HTML(raw []byte, _ uint32) bool
- func Hdr(raw []byte, _ uint32) bool
- func Heic(raw []byte, _ uint32) bool
- func HeicSequence(raw []byte, _ uint32) bool
- func Heif(raw []byte, _ uint32) bool
- func HeifSequence(raw []byte, _ uint32) bool
- func ICalendar(raw []byte, _ uint32) bool
- func Icns(raw []byte, _ uint32) bool
- func Ico(raw []byte, _ uint32) bool
- func InstallShieldCab(raw []byte, _ uint32) bool
- func JSON(raw []byte, limit uint32) bool
- func Jar(raw []byte, limit uint32) bool
- func Jp2(raw []byte, _ uint32) bool
- func Jpg(raw []byte, _ uint32) bool
- func Jpm(raw []byte, _ uint32) bool
- func Jpx(raw []byte, _ uint32) bool
- func Js(raw []byte, _ uint32) bool
- func Jxl(raw []byte, _ uint32) bool
- func Jxr(raw []byte, _ uint32) bool
- func Jxs(raw []byte, _ uint32) bool
- func KMZ(raw []byte, _ uint32) bool
- func Kml(raw []byte, _ uint32) bool
- func Lit(raw []byte, _ uint32) bool
- func Lnk(raw []byte, _ uint32) bool
- func Lotus123(raw []byte, _ uint32) bool
- func Lua(raw []byte, _ uint32) bool
- func Lzip(raw []byte, _ uint32) bool
- func M3u(raw []byte, _ uint32) bool
- func M4a(raw []byte, _ uint32) bool
- func M4v(raw []byte, _ uint32) bool
- func MachO(raw []byte, limit uint32) bool
- func Marc(raw []byte, limit uint32) bool
- func Midi(raw []byte, _ uint32) bool
- func Mj2(raw []byte, _ uint32) bool
- func Mkv(raw []byte, limit uint32) bool
- func Mobi(raw []byte, _ uint32) bool
- func Mp3(raw []byte, limit uint32) bool
- func Mp4(raw []byte, _ uint32) bool
- func Mpeg(raw []byte, limit uint32) bool
- func Mqv(raw []byte, _ uint32) bool
- func MsAccessAce(raw []byte, _ uint32) bool
- func MsAccessMdb(raw []byte, _ uint32) bool
- func Msg(raw []byte, limit uint32) bool
- func Msi(raw []byte, limit uint32) bool
- func MusePack(raw []byte, _ uint32) bool
- func NdJSON(raw []byte, limit uint32) bool
- func Nes(raw []byte, _ uint32) bool
- func NetPAM(raw []byte, _ uint32) bool
- func NetPBM(raw []byte, _ uint32) bool
- func NetPGM(raw []byte, _ uint32) bool
- func NetPPM(raw []byte, _ uint32) bool
- func Odc(raw []byte, _ uint32) bool
- func Odf(raw []byte, _ uint32) bool
- func Odg(raw []byte, _ uint32) bool
- func Odp(raw []byte, _ uint32) bool
- func Ods(raw []byte, _ uint32) bool
- func Odt(raw []byte, _ uint32) bool
- func Ogg(raw []byte, limit uint32) bool
- func OggAudio(raw []byte, limit uint32) bool
- func OggVideo(raw []byte, limit uint32) bool
- func Ole(raw []byte, limit uint32) bool
- func One(raw []byte, limit uint32) bool
- func Otf(raw []byte, _ uint32) bool
- func Otg(raw []byte, _ uint32) bool
- func Otp(raw []byte, _ uint32) bool
- func Ots(raw []byte, _ uint32) bool
- func Ott(raw []byte, _ uint32) bool
- func Owl2(raw []byte, _ uint32) bool
- func P7s(raw []byte, _ uint32) bool
- func PDF(raw []byte, _ uint32) bool
- func Par1(raw []byte, _ uint32) bool
- func Pat(raw []byte, _ uint32) bool
- func Pdf(raw []byte, _ uint32) bool
- func Perl(raw []byte, _ uint32) bool
- func Php(raw []byte, limit uint32) bool
- func Png(raw []byte, _ uint32) bool
- func Ppt(raw []byte, limit uint32) bool
- func Pptx(raw []byte, limit uint32) bool
- func Ps(raw []byte, _ uint32) bool
- func Psd(raw []byte, _ uint32) bool
- func Pub(raw []byte, limit uint32) bool
- func Python(raw []byte, _ uint32) bool
- func Qcp(raw []byte, limit uint32) bool
- func QuickTime(raw []byte, _ uint32) bool
- func RAR(raw []byte, _ uint32) bool
- func RPM(raw []byte, _ uint32) bool
- func Rmvb(raw []byte, _ uint32) bool
- func Rss(raw []byte, _ uint32) bool
- func Rtf(raw []byte, _ uint32) bool
- func Ruby(raw []byte, _ uint32) bool
- func SWF(raw []byte, _ uint32) bool
- func SevenZ(raw []byte, _ uint32) bool
- func Shell(raw []byte, _ uint32) bool
- func Shp(raw []byte, limit uint32) bool
- func Shx(raw []byte, limit uint32) bool
- func Sqlite(raw []byte, _ uint32) bool
- func Srt(raw []byte, _ uint32) bool
- func Svg(raw []byte, limit uint32) bool
- func Sxc(raw []byte, _ uint32) bool
- func TSV(raw []byte, limit uint32) bool
- func Tar(raw []byte, _ uint32) bool
- func Tcl(raw []byte, _ uint32) bool
- func Tcx(raw []byte, _ uint32) bool
- func Text(raw []byte, _ uint32) bool
- func ThreeG2(raw []byte, _ uint32) bool
- func ThreeGP(raw []byte, _ uint32) bool
- func Threemf(raw []byte, _ uint32) bool
- func Tiff(raw []byte, _ uint32) bool
- func Torrent(raw []byte, _ uint32) bool
- func Ttc(raw []byte, limit uint32) bool
- func Ttf(raw []byte, limit uint32) bool
- func TzIf(raw []byte, limit uint32) bool
- func VCard(raw []byte, _ uint32) bool
- func Visio(raw []byte, limit uint32) bool
- func Voc(raw []byte, _ uint32) bool
- func Vtt(raw []byte, limit uint32) bool
- func WPD(raw []byte, _ uint32) bool
- func Warc(raw []byte, _ uint32) bool
- func Wasm(raw []byte, _ uint32) bool
- func Wav(raw []byte, limit uint32) bool
- func WebM(raw []byte, limit uint32) bool
- func Webp(raw []byte, _ uint32) bool
- func Woff(raw []byte, _ uint32) bool
- func Woff2(raw []byte, _ uint32) bool
- func X3d(raw []byte, _ uint32) bool
- func XHTML(raw []byte, limit uint32) bool
- func XML(raw []byte, _ uint32) bool
- func Xar(raw []byte, _ uint32) bool
- func Xcf(raw []byte, _ uint32) bool
- func Xfdf(raw []byte, _ uint32) bool
- func Xliff(raw []byte, _ uint32) bool
- func Xls(raw []byte, limit uint32) bool
- func Xlsx(raw []byte, limit uint32) bool
- func Xpm(raw []byte, _ uint32) bool
- func Xz(raw []byte, _ uint32) bool
- func Zip(raw []byte, limit uint32) bool
- func Zstd(raw []byte, limit uint32) bool
- type Detector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APK ¶ added in v0.17.0
APK matches an Android Package Archive. The source of signatures is https://github.com/file/file/blob/1778642b8ba3d947a779a36fcd81f8e807220a19/magic/Magdir/archive#L1820-L1887
func AVIF ¶
AVIF matches an AV1 Image File Format still or animated. Wikipedia page seems outdated listing image/avif-sequence for animations. https://github.com/AOMediaCodec/av1-avif/issues/59
func Apng ¶
Apng matches an Animated Portable Network Graphics file. https://wiki.mozilla.org/APNG_Specification
func CBOR ¶
CBOR matches a Concise Binary Object Representation https://cbor.io/
func DXF ¶ added in v0.20.0
DXF matches Drawing Exchange Format AutoCAD file. There does not seem to be a clear specification and the files in the wild differ wildly. https://images.autodesk.com/adsk/files/autocad_2012_pdf_dxf-reference_enu.pdf
I collected these signatures by downloading a few dozen files from http://cd.textfiles.com/amigaenv/DXF/OBJEKTE/ and https://sembiance.com/fileFormatSamples/poly/dxf/ and then xxd -l 16 {} | sort | uniq. These signatures are only for the ASCII version of DXF. There is a binary version too.
func Dbf ¶
Dbf matches a dBase file. https://www.dbase.com/Knowledgebase/INT/db7_file_fmt.htm
func Doc ¶
Doc matches a Microsoft Word 97-2003 file. See: https://github.com/decalage2/oletools/blob/412ee36ae45e70f42123e835871bac956d958461/oletools/common/clsid.py
func Dvb ¶
Dvb matches a Digital Video Broadcasting file: https://dvb.org. https://cconcolato.github.io/mp4ra/filetype.html https://github.com/file/file/blob/512840337ead1076519332d24fefcaa8fac36e06/magic/Magdir/animation#L135-L154
func GLB ¶ added in v0.17.2
GLB matches a glTF model format file. GLB is the binary file format representation of 3D models saved in the GL transmission Format (glTF). GLB uses little endian and its header structure is as follows:
<-- 12-byte header --> | magic | version | length | | (uint32) | (uint32) | (uint32) | | \x67\x6C\x54\x46 | \x01\x00\x00\x00 | ... | | g l T F | 1 | ... |
Visit glTF specification and IANA glTF entry for more details.
func GLTF ¶ added in v0.17.2
GLTF matches a GL Transmission Format (JSON) file. Visit glTF specification and IANA glTF entry for more details.
func GeoJSON ¶
GeoJSON matches a RFC 7946 GeoJSON file.
GeoJSON detection implies searching for key:value pairs like: `"type": "Feature"` in the input.
func Gzip ¶
Gzip matches gzip files based on http://www.zlib.org/rfc-gzip.html#header-trailer.
func HAR ¶
HAR matches a HAR Spec file. Spec: http://www.softwareishard.com/blog/har-12-spec/
func Hdr ¶
Hdr matches Radiance HDR image. https://web.archive.org/web/20060913152809/http://local.wasp.uwa.edu.au/~pbourke/dataformats/pic/
func HeicSequence ¶
HeicSequence matches a High Efficiency Image Coding (HEIC) file sequence.
func HeifSequence ¶
HeifSequence matches a High Efficiency Image File Format (HEIF) file sequence.
func InstallShieldCab ¶
InstallShieldCab matches an InstallShield Cabinet archive file.
func Jar ¶
Jar matches a Java archive file. There are two types of Jar files: 1. the ones that can be opened with jexec and have 0xCAFE optional flag https://stackoverflow.com/tags/executable-jar/info 2. regular jars, same as above, just without the executable flag https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=262278#c0 There is an argument to only check for manifest, since it's the common nominator for both executable and non-executable versions. But the traversing zip entries is unreliable because it does linear search for signatures (instead of relying on offsets told by the file.)
func Mj2 ¶
Mj2 matches a Motion JPEG 2000 file: https://en.wikipedia.org/wiki/Motion_JPEG_2000.
func Mp4 ¶
Mp4 detects an .mp4 file. Mp4 detections only does a basic ftyp check. Mp4 has many registered and unregistered code points so it's hard to keep track of all. Detection will default on video/mp4 for all ftyp files. ISO_IEC_14496-12 is the specification for the iso container.
func MsAccessAce ¶
MsAccessAce matches Microsoft Access dababase file.
func MsAccessMdb ¶
MsAccessMdb matches legacy Microsoft Access database file (JET, 2003 and earlier).
func Msi ¶
Msi matches a Microsoft Windows Installer file. http://fileformats.archiveteam.org/wiki/Microsoft_Compound_File
func NdJSON ¶
NdJSON matches a Newline delimited JSON file. All complete lines from raw must be valid JSON documents meaning they contain one of the valid JSON data types.
func PDF ¶ added in v0.18.2
PDF matches a Portable Document Format file. The %PDF- header should be the first thing inside the file but many implementations don't follow the rule. The PDF spec at Appendix H says the signature can be prepended by anything. https://bugs.astron.com/view.php?id=446
func Pdf ¶
Pdf matches a Portable Document Format file. https://github.com/file/file/blob/11010cc805546a3e35597e67e1129a481aed40e8/magic/Magdir/pdf
func Png ¶
Png matches a Portable Network Graphics file. https://www.w3.org/TR/PNG/
func QuickTime ¶
QuickTime matches a QuickTime File Format file. https://www.loc.gov/preservation/digital/formats/fdd/fdd000052.shtml https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap1/qtff1.html#//apple_ref/doc/uid/TP40000939-CH203-38190 https://github.com/apache/tika/blob/0f5570691133c75ac4472c3340354a6c4080b104/tika-core/src/main/resources/org/apache/tika/mime/tika-mimetypes.xml#L7758-L7777
func Shp ¶
Shp matches a shape format file. https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
func Shx ¶
Shx matches a shape index format file. https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf
func Tar ¶
Tar matches a (t)ape (ar)chive file. Tar files are divided into 512 bytes records. First record contains a 257 bytes header padded with NUL.
func Text ¶
Text matches a plain text file.
TODO: This function does not parse BOM-less UTF16 and UTF32 files. Not really sure it should. Linux file utility also requires a BOM for UTF16 and UTF32.
func TzIf ¶
TzIf matches a Time Zone Information Format (TZif) file. See more: https://tools.ietf.org/id/draft-murchison-tzdist-tzif-00.html#rfc.section.3 Its header structure is shown below:
+---------------+---+ | magic (4) | <-+-- version (1) +---------------+---+---------------------------------------+ | [unused - reserved for future use] (15) | +---------------+---------------+---------------+-----------+ | isutccnt (4) | isstdcnt (4) | leapcnt (4) | +---------------+---------------+---------------+ | timecnt (4) | typecnt (4) | charcnt (4) |
func Vtt ¶
Vtt matches a Web Video Text Tracks (WebVTT) file. See https://www.iana.org/assignments/media-types/text/vtt.
func XHTML ¶ added in v0.20.0
XHTML matches an XHTML file. This check depends on the XML check to have passed.
func Xz ¶
Xz matches an xz compressed stream based on https://tukaani.org/xz/xz-file-format.txt.
Types ¶
type Detector ¶
Detector receiveѕ the raw data of a file and returns whether the data meets any conditions. The limit parameter is an upper limit to the number of bytes received and is used to tell if the byte slice represents the whole file or is just the header of a file: len(raw) < limit or len(raw)>limit.