MCPcopy Create free account
hub / github.com/cli/cli / BinaryContentType

Function BinaryContentType

pkg/iostreams/content.go:36–48  ·  view source on GitHub ↗

BinaryContentType reports whether content appears to be binary and, if so, returns its detected MIME type. Textual content returns ("", false).

(content []byte)

Source from the content-addressed store, hash-verified

34// BinaryContentType reports whether content appears to be binary and, if so,
35// returns its detected MIME type. Textual content returns ("", false).
36func BinaryContentType(content []byte) (string, bool) {
37 if len(content) == 0 {
38 return "", false
39 }
40 ct := http.DetectContentType(content)
41 if i := strings.IndexByte(ct, ';'); i >= 0 {
42 ct = strings.TrimSpace(ct[:i])
43 }
44 if strings.HasPrefix(ct, "text/") {
45 return "", false
46 }
47 return ct, true
48}
49
50// BinaryTerminalError reports that binary content was about to be written to a
51// terminal, where it is unreadable and may carry control bytes.

Callers 3

readFileRunFunction · 0.92
CopyGuardedContentFunction · 0.85
TestBinaryContentTypeFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestBinaryContentTypeFunction · 0.68