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

Function BinaryContentType

pkg/iostreams/content.go:24–36  ·  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

22// BinaryContentType reports whether content appears to be binary and, if so,
23// returns its detected MIME type. Textual content returns ("", false).
24func BinaryContentType(content []byte) (string, bool) {
25 if len(content) == 0 {
26 return "", false
27 }
28 ct := http.DetectContentType(content)
29 if i := strings.IndexByte(ct, ';'); i >= 0 {
30 ct = strings.TrimSpace(ct[:i])
31 }
32 if strings.HasPrefix(ct, "text/") {
33 return "", false
34 }
35 return ct, true
36}
37
38// BinaryTerminalError reports that binary content was about to be written to a
39// 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