isBinary determines if the provided `data` is likely binary content. It first checks if the given `contentType` (e.g., from an HTTP header) is a known binary MIME type. If not, it then scans the `data` byte slice for the presence of null bytes (0x00), which are a strong heuristic for binary data. Re
(response *http.Response, data []byte)
| 81 | // which are a strong heuristic for binary data. |
| 82 | // Returns `true` if identified as binary, `false` otherwise. |
| 83 | func isBinary(response *http.Response, data []byte) bool { |
| 84 | responseContextType := "" |
| 85 | if response != nil && response.Header != nil { |
| 86 | responseContextType = response.Header.Get("Content-Type") |
| 87 | } |
| 88 | if strings.Contains(responseContextType, "image/") || |
| 89 | strings.Contains(responseContextType, "application/octet-stream") || |
| 90 | strings.Contains(responseContextType, "application/pdf") { |
| 91 | return true |
| 92 | } |
| 93 | return bytes.ContainsRune(data, 0x00) // Check for null byte |
| 94 | } |