Debian Codegraph @

kind.go

raw symbols SCIP
1 package filetype
2
3 import (
4 "github.com/h2non/filetype/matchers"
5 "github.com/h2non/filetype/types"
6 )
7
8 // Image tries to match a file as image type
9 func Image(buf []byte) (types.Type, error) {
10 return doMatchMap(buf, matchers.Image)
11 }
12
13 // IsImage checks if the given buffer is an image type
14 func IsImage(buf []byte) bool {
15 kind, _ := Image(buf)
16 return kind != types.Unknown
17 }
18
19 // Audio tries to match a file as audio type
20 func Audio(buf []byte) (types.Type, error) {
21 return doMatchMap(buf, matchers.Audio)
22 }
23
24 // IsAudio checks if the given buffer is an audio type
25 func IsAudio(buf []byte) bool {
26 kind, _ := Audio(buf)
27 return kind != types.Unknown
28 }
29
30 // Video tries to match a file as video type
31 func Video(buf []byte) (types.Type, error) {
32 return doMatchMap(buf, matchers.Video)
33 }
34
35 // IsVideo checks if the given buffer is a video type
36 func IsVideo(buf []byte) bool {
37 kind, _ := Video(buf)
38 return kind != types.Unknown
39 }
40
41 // Font tries to match a file as text font type
42 func Font(buf []byte) (types.Type, error) {
43 return doMatchMap(buf, matchers.Font)
44 }
45
46 // IsFont checks if the given buffer is a font type
47 func IsFont(buf []byte) bool {
48 kind, _ := Font(buf)
49 return kind != types.Unknown
50 }
51
52 // Archive tries to match a file as generic archive type
53 func Archive(buf []byte) (types.Type, error) {
54 return doMatchMap(buf, matchers.Archive)
55 }
56
57 // IsArchive checks if the given buffer is an archive type
58 func IsArchive(buf []byte) bool {
59 kind, _ := Archive(buf)
60 return kind != types.Unknown
61 }
62
63 // Document tries to match a file as document type
64 func Document(buf []byte) (types.Type, error) {
65 return doMatchMap(buf, matchers.Document)
66 }
67
68 // IsDocument checks if the given buffer is an document type
69 func IsDocument(buf []byte) bool {
70 kind, _ := Document(buf)
71 return kind != types.Unknown
72 }
73
74 // Application tries to match a file as an application type
75 func Application(buf []byte) (types.Type, error) {
76 return doMatchMap(buf, matchers.Application)
77 }
78
79 // IsApplication checks if the given buffer is an application type
80 func IsApplication(buf []byte) bool {
81 kind, _ := Application(buf)
82 return kind != types.Unknown
83 }
84
85 func doMatchMap(buf []byte, machers matchers.Map) (types.Type, error) {
86 kind := MatchMap(buf, machers)
87 if kind != types.Unknown {
88 return kind, nil
89 }
90 return kind, ErrUnknownBuffer
91 }