-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknowns.go
More file actions
237 lines (221 loc) · 5.13 KB
/
knowns.go
File metadata and controls
237 lines (221 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package magicnumber
import (
"io"
)
// 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.
func Archive(r io.ReaderAt) (Signature, error) {
find := *New()
for _, archive := range Archives() {
if finder, exists := find[archive]; exists {
if finder(r) {
return archive, nil
}
}
}
return Unknown, nil
}
// Archives returns all the archive file type signatures.
func Archives() []Signature {
return []Signature{
PKWAREZipShrink,
PKWAREZipReduce,
PKWAREZipImplode,
PKWAREZip64,
PKWAREZip,
PKWAREMultiVolume,
PKLITE,
PKSFX,
TapeARchive,
RoshalARchive,
RoshalARchivev5,
GzipCompressArchive,
Bzip2CompressArchive,
X7zCompressArchive,
XZCompressArchive,
ZStandardArchive,
FreeArc,
ARChiveSEA,
YoshiLHA,
ZooArchive,
ArchiveRobertJung,
MicrosoftCABinet,
}
}
// 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.
func DiscImage(r io.ReaderAt) (Signature, error) {
find := *New()
for _, img := range DiscImages() {
if finder, exists := find[img]; exists {
if finder(r) {
return img, nil
}
}
}
return Unknown, nil
}
// DiscImages returns all the CD disk image file type signatures.
func DiscImages() []Signature {
return []Signature{
CDISO9660,
CDNero,
CDPowerISO,
CDAlcohol120,
}
}
// ArchivesBBS returns all the archive file type signatures that were
// commonly used in the BBS online era of the 1980s and early 1990s.
// Eventually these were replaced by the universal ZIP format using
// the Deflate and Store compression methods.
func ArchivesBBS() []Signature {
return []Signature{
PKWAREZipShrink,
PKWAREZipReduce,
PKWAREZipImplode,
ARChiveSEA,
YoshiLHA,
ZooArchive,
ArchiveRobertJung,
}
}
// 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.
func Document(r io.ReaderAt) (Signature, error) {
find := *New()
for _, doc := range Documents() {
if finder, exists := find[doc]; exists {
if finder(r) {
return doc, nil
}
}
}
switch {
case Ansi(r):
return ANSIEscapeText, nil
case CodePage(r), Txt(r):
return PlainText, nil
default:
return Unknown, nil
}
}
func Documents() []Signature {
return []Signature{
WindowsHelpFile,
PortableDocumentFormat,
RichTextFormat,
UTF8Text,
UTF16Text,
UTF32Text,
}
}
// 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.
func Image(r io.ReaderAt) (Signature, error) {
find := *New()
for _, img := range Images() {
if finder, exists := find[img]; exists {
if finder(r) {
return img, nil
}
}
}
return Unknown, nil
}
// Images returns all the image file type signatures.
func Images() []Signature {
return []Signature{
AV1ImageFile,
JPEGFileInterchangeFormat,
JPEG2000,
PortableNetworkGraphics,
GraphicsInterchangeFormat,
GoogleWebP,
TaggedImageFileFormat,
BMPFileFormat,
PersonalComputereXchange,
InterleavedBitmap,
MicrosoftIcon,
RIPscrip,
ElectronicArtsAnim,
}
}
// 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.
func Program(r io.ReaderAt) (Signature, error) {
find := *New()
for _, app := range Programs() {
if finder, exists := find[app]; exists {
if finder(r) {
return app, nil
}
}
}
return Unknown, nil
}
// Programs returns all the program file type signatures for
// Microsoft operating systems, DOS and Windows.
func Programs() []Signature {
return []Signature{
MicrosoftExecutable,
MicrosoftDOSKWAJ,
MicrosoftDOSSZDD,
MicrosoftCompoundFile,
}
}
// 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.
func Text(r io.ReaderAt) (Signature, error) {
find := *New()
for _, doc := range Texts() {
if finder, exists := find[doc]; exists {
if finder(r) {
return doc, nil
}
}
}
switch {
case Ansi(r):
return ANSIEscapeText, nil
case CodePage(r), Txt(r):
return PlainText, nil
default:
return Unknown, nil
}
}
// Texts returns all the text file type signatures.
func Texts() []Signature {
return []Signature{
UTF8Text,
UTF16Text,
UTF32Text,
ANSIEscapeText,
PlainText,
}
}
// 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.
func Video(r io.ReaderAt) (Signature, error) {
find := *New()
for _, vid := range Videos() {
if finder, exists := find[vid]; exists {
if finder(r) {
return vid, nil
}
}
}
return Unknown, nil
}
// Videos returns all the video file type signatures.
func Videos() []Signature {
return []Signature{
MPEG4,
QuickTimeMovie,
QuickTimeM4V,
MicrosoftAudioVideoInterleave,
MicrosoftWindowsMedia,
MPEG,
FlashVideo,
RealPlayer,
}
}