# README
Defacto2 / magicnumber
The magicnumber package is to read the bytes within a file to learn of the format or type of file. This is useful for identifying the file without relying on the file extension or MIME type. See the reference documentation for additional usage and examples.
package main
import (
"fmt"
"log"
"os"
"github.com/Defacto2/magicnumber"
)
func main() {
file, err := os.Open("example.exe")
if err != nil {
log.Fatal(err)
}
defer file.Close()
mn, err := magicnumber.Find(file)
if err != nil {
log.Fatal(err)
}
fmt.Printf("File type: %s\n", mn.Type)
fmt.Printf("File extension: %s\n", mn.Extension)
}
# Functions
AAC matches the Advanced Audio Coding audio format.
Ansi returns true if the reader contains some common ANSI escape codes.
ArcFree matches the FreeArc compression format.
Archive reads all the bytes from the reader and returns the file type signature if the file is a known archive of files or Unknown if the file is not an archive.
Archives returns all the archive file type signatures.
Archives returns all the archive file type signatures that were commonly used in the BBS online era of the 1980s and early 1990s.
ArcSEA matches the ARChive SEA compression format.
Arj matches ARJ compression format.
ASCII returns true if the reader exclusively contains printable ASCII characters.
Avi matches the Microsoft Audio Video Interleave video format.
Avif matches the AV1 Image File image format in the byte slice, also known as AVIF.
Bmp matches the BMP image format.
Bzip2 matches the Bzip2 Compress archive format.
Cab matches the Microsoft CABinet archive format.
CodePage returns true if the reader contains is a possible IBM code page text file that was often found on DOS and 16-bit Windows computers.
ConvLatin1 converts a byte slice to a Latin-1 (ISO-8859-1) string.
ConvSize converts a byte slice to an integer.
CSI returns true if the reader contains three or more common Control Sequence Introducer (CSI) escape codes that are used in ANSI encoded texts.
Daa returns true if the reader contains the PowerISO DAA CD image signature.
No description provided by the author
DiscImage reads all the bytes from the reader and returns the file type signature if the file is a known CD disk image or Unknown if the file is not a disk image.
DiscImages returns all the CD disk image file type signatures.
Document reads all the bytes from the reader and returns the file type signature if the file is a known document or Unknown if the file is not a document.
No description provided by the author
DosKWAJ returns true if the reader begins with the KWAJ compression signature, found in some DOS executables.
DosSZDD returns true if the reader begins with the SZDD compression signature.
Empty returns true if the reader is empty.
Ext returns a map of file type signatures to common file extensions.
Find returns the file type signature from the byte slice.
FindExecutable reads the first 1KB from the reader and returns the specific information contained within the executable headers.
Flac matches the Free Lossless Audio Codec audio format.
Flv matches the Shockwave Flash Video format.
Gif matches the image Graphics Interchange Format.
Gzip matches the Gzip Compress archive format.
Hlp returns true if the reader contains the Windows Help File signature.
Ico matches the Microsoft Icon image format.
ID3v220 reads the [ID3 v2.2] tags in the byte slice and returns the song, artist and year.
ID3v22Frame reads the ID3 v2.2 frame in the byte slice and returns the frame data as a string.
ID3v230 reads the [ID3 v2.3] and ID3 v2.4 tags in the byte slice and returns the song, artist and year.
ID3v23Frame reads the ID3 v2.3 and v2.4 frame in the byte slice and returns the frame data as a string.
Iff matches the Interchange File Format image.
Ilbm matches the InterLeaved Bitmap image format.
IlbmDecode reads the InterLeaved Bitmap image format in the reader and returns the width and height.
Image reads all the bytes from the reader and returns the file type signature if the file is a known image or Unknown if the file is not an image.
Images returns all the image file type signatures.
ISO returns true if the reader contains the ISO 9660 CD-ROM filesystem signature.
IT matches the Impulse Tracker music format.
Ivr matches the RealPlayer video format.
Jpeg matches the JPEG File Interchange Format v1 image.
Jpeg2000 matches the JPEG 2000 image format.
JpegNoSuffix matches the JPEG File Interchange Format v1 image.
Length returns the length of the reader.
LzhLha matches the LHA and LZH compression formats.
M4v matches the QuickTime M4V video format.
MatchExt determines if the reader matches the file type signature expected from the extension of the filename.
Mdf returns true if the reader contains the Alcohol 120% MDF CD image signature.
Midi matches the Musical Instrument Digital Interface (MIDI) format.
MK matches the ProTracker MOD music format.
Mp3 matches the MPEG-1 Audio Layer 3 audio format.
Mp4 matches the MPEG-4 video format.
Mpeg matches the MPEG video format.
MSComp returns true if the reader contains the Microsoft Compound File signature.
MSExe returns true if the reader begins with the Microsoft executable signature.
MTM matches the MultiTracker music format.
MusicID3v1 reads the [ID3 v1] tag in the byte slice and returns the song, artist and year.
MusicID3v2 reads the [ID3 v2] tag in the byte slice and returns the song, artist and year.
MusicIT returns the [Impulse Tracker] song or title in the byte slice if available.
MusicMK returns the MOD song or title in the byte slice if available.
MusicMTM returns the [MultiTracker] song or title in the byte slice if available.
MusicMod returns the tracked music format in the byte slice and the name or title of the song if available.
MusicXM returns the [eXtended Module] song or title in the byte slice if available.
NE returns the New Executable file type from the byte slice.
New returns a new Finder with all the matchers.
NonISO889591 returns true if the byte is not a printable ISO/IEC-8895-1 character.
NonWindows1252 returns true if the byte is not a printable Windows-1252 character.
NotASCII returns true if the byte is not an printable ASCII character.
NotPlainText returns true if the byte is not a printable plain text character.
Nri returns true if the reader contains the Nero CD image signature.
Ogg matches the Ogg Vorbis audio format.
Pcx matches the Personal Computer eXchange image format.
Pdf returns true if the reader contains the Portable Document Format signature.
PE returns the Portable Executable file type from the byte slice.
PkImplode matches the PKWARE Implode method zip archive format.
Pklite matches the PKLITE archive format in the byte slice which is a compressed executable format for DOS and 16-bit Windows.
PkReduce matches the PKWARE Reduce method zip archive format.
Pksfx matches the PKSFX archive format in the byte slice which is a self-extracting archive format.
PkShrink matches the PKWARE Shrink method zip archive format.
Pkzip matches the zip archive format.
PkzipMulti matches the PKWARE Multi-Volume Zip archive format.
Png matches the Portable Network Graphics image format.
Program reads all the bytes from the reader and returns the file type signature if the file is a known DOS or Windows program or Unknown if the file is not a program.
Programs returns all the program file type signatures for Microsoft operating systems, DOS and Windows.
QTMov matches the QuickTime Movie video format.
Rar matches the Roshal ARchive format.
Rarv5 matches the Roshal ARchive v5 format.
No description provided by the author
Ripscrip returns true if the reader contains the RIPscrip signature.
Rtf returns true if the reader contains the Rich Text Format signature.
Tar matches the Tape ARchive format.
Text reads the first 512 bytes from the reader and returns the file type signature if the file is a known plain text file or Unknown if the file is not a text file.
Texts returns all the text file type signatures.
Tiff matches the Tagged Image File Format.
Txt returns true if the reader exclusively contains plain text ASCII characters, control characters or "extended ASCII characters".
TxtLatin1 returns true if the reader exclusively contains plain text ISO/IEC-8895-1 characters, commonly known as the Latin-1 character set.
TxtWindows returns true if the reader exclusively contains plain text Windows-1252 characters.
Utf16 returns true if the reader beings with the UTF-16 Byte Order Mark signature.
Utf32 returns true if the reader beings with the UTF-32 Byte Order Mark signature.
Utf8 returns true if the reader begins with the UTF-8 Byte Order Mark signature.
Video reads all the bytes from the reader and returns the file type signature if the file is a known video or Unknown if the file is not a video.
Videos returns all the video file type signatures.
Wave matches the IBM / Microsoft Waveform audio format.
Webp matches the Google WebP image format.
WindowsNames returns the Windows version names and their minimum version numbers.
Wmv matches the Microsoft Windows Media video format.
X7z matches the 7z Compress archive format.
XM matches the eXtended Module tracked music format.
XZ matches the XZ Compress archive format.
Zip64 matches the PKWARE Zip64 archive format.
Zoo matches the Zoo compression format.
ZStd matches the ZStandard archive format.
# Constants
AMD64 Portable Executable.
No description provided by the author
No description provided by the author
No description provided by the author
ARM64 Portable Executable.
ARM Portable Executable.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
MS-DOS v4 New Executable.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ID3v1Size is the minimum buffer size of an ID3 v1 tag.
Intel 386 Portable Executable.
No description provided by the author
Itanium Portable Executable.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Not a New Executable.
No description provided by the author
Microsoft IBM OS/2 New Executable.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Unknown New Executable.
Unknown Portable Executable.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Windows requiring an Intel 286 CPU New Executable.
Windows requiring an Intel 386 CPU New Executable.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
No description provided by the author
# Type aliases
Extension is a map of file type signatures to file extensions.
Finder is a map of file type signatures to matchers.
Matcher is a function that matches a byte slice to a file type.
NewExecutable represents the New Executable file type, a format used by Microsoft and IBM from the mid-1980s to improve on the limitations of the MS-DOS MZ executable format.
PortableExecutable represents the Portable Executable file type, a format used by Microsoft for executables, object code, DLLs, FON Font files, and others.
Signature represents a file type signature.
WindowsName represents the Windows version names and their minimum version numbers.