BinaryContentType reports whether content appears to be binary and, if so, returns its detected MIME type. Textual content returns ("", false).
(content []byte)
| 34 | // BinaryContentType reports whether content appears to be binary and, if so, |
| 35 | // returns its detected MIME type. Textual content returns ("", false). |
| 36 | func 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. |
no outgoing calls