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