MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / checkFileHead

Function checkFileHead

opensca/walk/magic.go:39–59  ·  view source on GitHub ↗

checkFileHead 检查文件头

(abspath string, ms ...Magic)

Source from the content-addressed store, hash-verified

37
38// checkFileHead 检查文件头
39func checkFileHead(abspath string, ms ...Magic) bool {
40 reader, err := os.Open(abspath)
41 if err != nil {
42 logs.Warn(err)
43 return false
44 }
45 defer reader.Close()
46 for _, m := range ms {
47 if len(m) == 0 {
48 continue
49 }
50 h := make([]byte, len(m))
51 reader.Seek(0, io.SeekStart)
52 reader.Read(h)
53 reader.Seek(0, io.SeekStart)
54 if bytes.Equal(m, h) {
55 return true
56 }
57 }
58 return false
59}

Callers 4

xgzFunction · 0.85
xbz2Function · 0.85
xrarFunction · 0.85
xzipFunction · 0.85

Calls 3

WarnFunction · 0.92
EqualMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected