/
kind.go
69 lines (57 loc) · 1.65 KB
/
kind.go
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
package filetype
import (
"gopkg.in/h2non/filetype.v1/matchers"
"gopkg.in/h2non/filetype.v1/types"
)
// Image tries to match a file as image type
func Image(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Image)
}
// IsImage checks if the given buffer is an image type
func IsImage(buf []byte) bool {
kind, _ := Image(buf)
return kind != types.Unknown
}
// Audio tries to match a file as audio type
func Audio(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Audio)
}
// IsAudio checks if the given buffer is an audio type
func IsAudio(buf []byte) bool {
kind, _ := Audio(buf)
return kind != types.Unknown
}
// Video tries to match a file as video type
func Video(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Video)
}
// IsVideo checks if the given buffer is a video type
func IsVideo(buf []byte) bool {
kind, _ := Video(buf)
return kind != types.Unknown
}
// Font tries to match a file as text font type
func Font(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Font)
}
// IsFont checks if the given buffer is a font type
func IsFont(buf []byte) bool {
kind, _ := Font(buf)
return kind != types.Unknown
}
// Archive tries to match a file as generic archive type
func Archive(buf []byte) (types.Type, error) {
return doMatchMap(buf, matchers.Archive)
}
// IsArchive checks if the given buffer is an audio type
func IsArchive(buf []byte) bool {
kind, _ := Archive(buf)
return kind != types.Unknown
}
func doMatchMap(buf []byte, machers matchers.Map) (types.Type, error) {
kind := MatchMap(buf, machers)
if kind != types.Unknown {
return kind, nil
}
return kind, ErrUnknownBuffer
}