MCPcopy
hub / github.com/cloudfoundry/cli / isBinary

Function isBinary

command/v7/curl_command.go:83–94  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

81// which are a strong heuristic for binary data.
82// Returns `true` if identified as binary, `false` otherwise.
83func 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}

Callers 1

ExecuteMethod · 0.85

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected