forked from h2non/filetype
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkind.go
More file actions
64 lines (53 loc) · 1.51 KB
/
kind.go
File metadata and controls
64 lines (53 loc) · 1.51 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
package filetype
// Image tries to match a file as image type
func MatchImage(buf []byte) (Typed, error) {
return doMatchMap(buf, Image)
}
// IsImage checks if the given buffer is an image type
func IsImage(buf []byte) bool {
kind, _ := MatchImage(buf)
return kind != Unknown
}
// Audio tries to match a file as audio type
func MatchAudio(buf []byte) (Typed, error) {
return doMatchMap(buf, Audio)
}
// IsAudio checks if the given buffer is an audio type
func IsAudio(buf []byte) bool {
kind, _ := MatchAudio(buf)
return kind != Unknown
}
// Video tries to match a file as video type
func MatchVideo(buf []byte) (Typed, error) {
return doMatchMap(buf, Video)
}
// IsVideo checks if the given buffer is a video type
func IsVideo(buf []byte) bool {
kind, _ := MatchVideo(buf)
return kind != Unknown
}
// Font tries to match a file as text font type
func MatchFont(buf []byte) (Typed, error) {
return doMatchMap(buf, Font)
}
// IsFont checks if the given buffer is a font type
func IsFont(buf []byte) bool {
kind, _ := MatchFont(buf)
return kind != Unknown
}
// Archive tries to match a file as generic archive type
func MatchArchive(buf []byte) (Typed, error) {
return doMatchMap(buf, Archive)
}
// IsArchive checks if the given buffer is an archive type
func IsArchive(buf []byte) bool {
kind, _ := MatchArchive(buf)
return kind != Unknown
}
func doMatchMap(buf []byte, mmapFunc MapOfMatcherFunc) (Typed, error) {
kind := MatchMap(buf, mmapFunc)
if kind != Unknown {
return kind, nil
}
return kind, ErrUnknownBuffer
}