MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / DetectBinary

Function DetectBinary

agent/utils/files/fileinfo.go:534–552  ·  view source on GitHub ↗
(buf []byte)

Source from the content-addressed store, hash-verified

532}
533
534func DetectBinary(buf []byte) bool {
535 mimeType := http.DetectContentType(buf)
536 if IsBinaryPreviewFile(mimeType, "") {
537 return true
538 }
539 if !strings.HasPrefix(mimeType, "text/") {
540 whiteByte := 0
541 n := min(1024, len(buf))
542 for i := 0; i < n; i++ {
543 if (buf[i] >= 0x20) || buf[i] == 9 || buf[i] == 10 || buf[i] == 13 {
544 whiteByte++
545 } else if buf[i] <= 6 || (buf[i] >= 14 && buf[i] <= 31) {
546 return true
547 }
548 }
549 return whiteByte < 1
550 }
551 return false
552}
553
554func min(x, y int) int {
555 if x < y {

Callers 1

getContentMethod · 0.85

Calls 2

IsBinaryPreviewFileFunction · 0.85
minFunction · 0.85

Tested by

no test coverage detected