MCPcopy Create free account
hub / github.com/anus-dev/ANUS / isBinary

Function isBinary

packages/core/src/utils/textUtils.ts:15–35  ·  view source on GitHub ↗
(
  data: Buffer | null | undefined,
  sampleSize = 512,
)

Source from the content-addressed store, hash-verified

13 * @returns True if a NULL byte is found, false otherwise.
14 */
15export function isBinary(
16 data: Buffer | null | undefined,
17 sampleSize = 512,
18): boolean {
19 if (!data) {
20 return false;
21 }
22
23 const sample = data.length > sampleSize ? data.subarray(0, sampleSize) : data;
24
25 for (const byte of sample) {
26 // The presence of a NULL byte (0x00) is one of the most reliable
27 // indicators of a binary file. Text files should not contain them.
28 if (byte === 0) {
29 return true;
30 }
31 }
32
33 // If no NULL bytes were found in the sample, we assume it's text.
34 return false;
35}

Callers 2

handleOutputMethod · 0.85
useShellCommandProcessorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected