filetype

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 7 Imported by: 2

README

filetype

doc

Detect the filetypes of binary data.

Documentation

Overview

Package filetype provides functions to identify file types of binary data.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Empty is a file type for empty files.
	Empty = newFiletype("empty", types.Unknown, func(b []byte) bool { return len(b) == 0 }, 1000)
	// Binary is the default file type for non-empty files.
	Binary = newFiletype("binary", types.Unknown, func(b []byte) bool { return len(b) > 0 }, 1000)
	// Text is a file type for files that only contains ascii characters.
	Text = &Filetype{"text", types.NewMIME("text/plain"), []string{"txt"}, isASCII, 900}
)
View Source
var (
	// MBR is the file type for the MBR partition system.
	MBR = &Filetype{"mbr", types.NewMIME("filesystem/mbr"), []string{"dd"}, MBRMatch, 1}
	// GPT is the file type for the GPT partition system.
	GPT = &Filetype{"gpt", types.NewMIME("filesystem/gpt"), []string{"dd"}, GPTMatch, 0}
	// FAT16 is the file type for the FAT16 file system.
	FAT16 = &Filetype{"fat16", types.NewMIME("filesystem/fat16"), []string{"dd"}, FAT16Match, 0}
	// HFSPlus is the file type for the HFSPlus file system.
	HFSPlus = &Filetype{"hfsplus", types.NewMIME("filesystem/hfsplus"), []string{"dd"}, HFSPlusMatch, 0}
	// ExFAT is the file type for the ExFAT file system.
	ExFAT = &Filetype{"exfat", types.NewMIME("filesystem/exfat"), []string{"dd"}, ExFATMatch, 0}
	// NTFS is the file type for the NTFS file system.
	NTFS = &Filetype{"ntfs", types.NewMIME("filesystem/ntfs"), []string{"dd"}, NTFSMatch, 0}

	// AFF4 is the file type for the AFF4 forensic image format.
	AFF4 = &Filetype{"aff4", types.NewMIME("filesystem/aff4"), []string{"aff4"}, AFF4Match, 0}
)
View Source
var (

	// Wasm is the file type for Wasm files.
	Wasm = newFiletype("wasm", matchers.TypeWasm, matchers.Wasm, 0)

	// Epub is the file type for Epub files.
	Epub = newFiletype("epub", matchers.TypeEpub, matchers.Epub, 0)
	// Zip is the file type for Zip files.
	Zip = newFiletype("zip", matchers.TypeZip, matchers.Zip, 10)
	// Tar is the file type for Tar files.
	Tar = newFiletype("tar", matchers.TypeTar, matchers.Tar, 0)
	// Rar is the file type for Rar files.
	Rar = newFiletype("rar", matchers.TypeRar, matchers.Rar, 0)
	// Gz is the file type for Gz files.
	Gz = newFiletype("gz", matchers.TypeGz, matchers.Gz, 0)
	// Bz2 is the file type for Bz2 files.
	Bz2 = newFiletype("bz2", matchers.TypeBz2, matchers.Bz2, 0)
	// Sevenz is the file type for Sevenz files.
	Sevenz = newFiletype("7z", matchers.Type7z, matchers.SevenZ, 0)
	// Xz is the file type for Xz files.
	Xz = newFiletype("xz", matchers.TypeXz, matchers.Xz, 0)
	// Pdf is the file type for Pdf files.
	Pdf = newFiletype("pdf", matchers.TypePdf, matchers.Pdf, 0)
	// Exe is the file type for Exe files.
	Exe = newFiletype("exe", matchers.TypeExe, matchers.Exe, 0)
	// Swf is the file type for Swf files.
	Swf = newFiletype("swf", matchers.TypeSwf, matchers.Swf, 0)
	// Rtf is the file type for Rtf files.
	Rtf = newFiletype("rtf", matchers.TypeRtf, matchers.Rtf, 0)
	// Eot is the file type for Eot files.
	Eot = newFiletype("eot", matchers.TypeEot, matchers.Eot, 0)
	// Ps is the file type for Ps files.
	Ps = newFiletype("ps", matchers.TypePs, matchers.Ps, 0)
	// Sqlite is the file type for Sqlite files.
	Sqlite = newFiletype("sqlite", matchers.TypeSqlite, matchers.Sqlite, 0)
	// Nes is the file type for Nes files.
	Nes = newFiletype("nes", matchers.TypeNes, matchers.Nes, 0)
	// Crx is the file type for Crx files.
	Crx = newFiletype("crx", matchers.TypeCrx, matchers.Crx, 0)
	// Cab is the file type for Cab files.
	Cab = newFiletype("cab", matchers.TypeCab, matchers.Cab, 0)
	// Deb is the file type for Deb files.
	Deb = newFiletype("deb", matchers.TypeDeb, matchers.Deb, 0)
	// Ar is the file type for Ar files.
	Ar = newFiletype("ar", matchers.TypeAr, matchers.Ar, 0)
	// Z is the file type for Z files.
	Z = newFiletype("Z      =", matchers.TypeZ, matchers.Z, 0)
	// Lz is the file type for Lz files.
	Lz = newFiletype("lz", matchers.TypeLz, matchers.Lz, 0)
	// Rpm is the file type for Rpm files.
	Rpm = newFiletype("rpm", matchers.TypeRpm, matchers.Rpm, 0)
	// Elf is the file type for Elf files.
	Elf = newFiletype("elf", matchers.TypeElf, matchers.Elf, 0)
	// Dcm is the file type for Dcm files.
	Dcm = newFiletype("dcm", matchers.TypeDcm, matchers.Dcm, 0)
	// Iso is the file type for Iso files.
	Iso = newFiletype("iso", matchers.TypeIso, matchers.Iso, 0)

	// Midi is the file type for Midi files.
	Midi = newFiletype("midi", matchers.TypeMidi, matchers.Midi, 0)
	// Mp3 is the file type for Mp3 files.
	Mp3 = newFiletype("mp3", matchers.TypeMp3, matchers.Mp3, 0)
	// M4a is the file type for M4a files.
	M4a = newFiletype("m4a", matchers.TypeM4a, matchers.M4a, 0)
	// Ogg is the file type for Ogg files.
	Ogg = newFiletype("ogg", matchers.TypeOgg, matchers.Ogg, 0)
	// Flac is the file type for Flac files.
	Flac = newFiletype("flac", matchers.TypeFlac, matchers.Flac, 0)
	// Wav is the file type for Wav files.
	Wav = newFiletype("wav", matchers.TypeWav, matchers.Wav, 0)
	// Amr is the file type for Amr files.
	Amr = newFiletype("amr", matchers.TypeAmr, matchers.Amr, 0)
	// Aac is the file type for Aac files.
	Aac = newFiletype("aac", matchers.TypeAac, matchers.Aac, 0)

	// Doc is the file type for Doc files.
	Doc = newFiletype("doc", matchers.TypeDoc, matchers.Doc, 0)
	// Docx is the file type for Docx files.
	Docx = newFiletype("docx", matchers.TypeDocx, matchers.Docx, 0)
	// Xls is the file type for Xls files.
	Xls = newFiletype("xls", matchers.TypeXls, matchers.Xls, 0)
	// Xlsx is the file type for Xlsx files.
	Xlsx = newFiletype("xlsx", matchers.TypeXlsx, matchers.Xlsx, 0)
	// Ppt is the file type for Ppt files.
	Ppt = newFiletype("ppt", matchers.TypePpt, matchers.Ppt, 0)
	// Pptx is the file type for Pptx files.
	Pptx = newFiletype("pptx", matchers.TypePptx, matchers.Pptx, 0)

	// Woff is the file type for Woff files.
	Woff = newFiletype("woff", matchers.TypeWoff, matchers.Woff, 0)
	// Woff2 is the file type for Woff2 files.
	Woff2 = newFiletype("woff2", matchers.TypeWoff2, matchers.Woff2, 0)
	// Ttf is the file type for Ttf files.
	Ttf = newFiletype("ttf", matchers.TypeTtf, matchers.Ttf, 0)
	// Otf is the file type for Otf files.
	Otf = newFiletype("otf", matchers.TypeOtf, matchers.Otf, 0)

	// Jpeg is the file type for Jpeg files.
	Jpeg = newFiletype("jpeg", matchers.TypeJpeg, matchers.Jpeg, 0)
	// Jpeg2000 is the file type for Jpeg2000 files.
	Jpeg2000 = newFiletype("jpeg2000", matchers.TypeJpeg2000, matchers.Jpeg2000, 0)
	// Png is the file type for Png files.
	Png = newFiletype("png", matchers.TypePng, matchers.Png, 0)
	// Gif is the file type for Gif files.
	Gif = newFiletype("gif", matchers.TypeGif, matchers.Gif, 0)
	// Webp is the file type for Webp files.
	Webp = newFiletype("webp", matchers.TypeWebp, matchers.Webp, 0)
	// CR2 is the file type for CR2 files.
	CR2 = newFiletype("cr2", matchers.TypeCR2, matchers.CR2, 0)
	// Tiff is the file type for Tiff files.
	Tiff = newFiletype("tiff", matchers.TypeTiff, matchers.Tiff, 0)
	// Bmp is the file type for Bmp files.
	Bmp = newFiletype("bmp", matchers.TypeBmp, matchers.Bmp, 0)
	// Jxr is the file type for Jxr files.
	Jxr = newFiletype("jxr", matchers.TypeJxr, matchers.Jxr, 0)
	// Psd is the file type for Psd files.
	Psd = newFiletype("psd", matchers.TypePsd, matchers.Psd, 0)
	// Ico is the file type for Ico files.
	Ico = newFiletype("ico", matchers.TypeIco, matchers.Ico, 0)
	// Heif is the file type for Heif files.
	Heif = newFiletype("heif", matchers.TypeHeif, matchers.Heif, 0)
	// Dwg is the file type for Dwg files.
	Dwg = newFiletype("dwg", matchers.TypeDwg, matchers.Dwg, 0)

	// Mp4 is the file type for Mp4 files.
	Mp4 = newFiletype("mp4", matchers.TypeMp4, matchers.Mp4, 0)
	// M4v is the file type for M4v files.
	M4v = newFiletype("m4v", matchers.TypeM4v, matchers.M4v, 0)
	// Mkv is the file type for Mkv files.
	Mkv = newFiletype("mkv", matchers.TypeMkv, matchers.Mkv, 0)
	// Webm is the file type for Webm files.
	Webm = newFiletype("webm", matchers.TypeWebm, matchers.Webm, 0)
	// Mov is the file type for Mov files.
	Mov = newFiletype("mov", matchers.TypeMov, matchers.Mov, 0)
	// Avi is the file type for Avi files.
	Avi = newFiletype("avi", matchers.TypeAvi, matchers.Avi, 0)
	// Wmv is the file type for Wmv files.
	Wmv = newFiletype("wmv", matchers.TypeWmv, matchers.Wmv, 0)
	// Mpeg is the file type for Mpeg files.
	Mpeg = newFiletype("mpeg", matchers.TypeMpeg, matchers.Mpeg, 0)
	// Flv is the file type for Flv files.
	Flv = newFiletype("flv", matchers.TypeFlv, matchers.Flv, 0)
	// Threegp is the file type for 3gp files.
	Threegp = newFiletype("3gp", matchers.Type3gp, matchers.Match3gp, 0)
)

Functions

func AFF4Match

func AFF4Match(buf []byte) bool

func ExFATMatch

func ExFATMatch(buf []byte) bool

ExFATMatch checks if the buffer matches a signature for ExFAT file systems.

func FAT16Match

func FAT16Match(buf []byte) bool

FAT16Match checks if the buffer matches a signature for FAT16 file systems.

func GPTMatch

func GPTMatch(buf []byte) bool

GPTMatch checks if the buffer matches a signature for GPT file systems.

func HFSPlusMatch

func HFSPlusMatch(buf []byte) bool

HFSPlusMatch checks if the buffer matches a signature for HFSPlus file systems.

func MBRMatch

func MBRMatch(buf []byte) bool

MBRMatch checks if the buffer matches a signature for MBR file systems.

func NTFSMatch

func NTFSMatch(buf []byte) bool

NTFSMatch checks if the buffer matches a signature for NTFS file systems.

Types

type Filetype

type Filetype struct {
	ID         ID
	Mimetype   types.MIME
	Extensions []string
	Matcher    func(buf []byte) bool
	// contains filtered or unexported fields
}

Filetype represents a single file format.

func Detect

func Detect(buf []byte) *Filetype

Detect identifies a Filetype a byte slice.

func DetectByExtension

func DetectByExtension(buf []byte, guess string) *Filetype

DetectByExtension identifies a Filetype a byte slice, the guess is used for performance.

func DetectReader

func DetectReader(r *bufio.Reader) (*Filetype, error)

DetectReader identifies a Filetype for an io.Reader.

func DetectReaderByExtension

func DetectReaderByExtension(r io.Reader, guess string) (*Filetype, error)

DetectReaderByExtension identifies a Filetype for an io.Reader, the guess is used for performance.

type ID

type ID string

ID stores a unique identifier for filetypes.

Jump to

Keyboard shortcuts

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