MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / isLikelyBinarySample

Function isLikelyBinarySample

projects/runtime-node/src/fileMetadata.ts:102–120  ·  view source on GitHub ↗
(sample: Uint8Array)

Source from the content-addressed store, hash-verified

100}
101
102function isLikelyBinarySample(sample: Uint8Array): boolean {
103 if (sample.length === 0) return false
104 if (sample.includes(0)) return true
105
106 try {
107 utf8Decoder.decode(sample)
108 } catch {
109 return true
110 }
111
112 let suspiciousControlBytes = 0
113 for (const byte of sample) {
114 if (byte < 0x20 && byte !== 0x08 && byte !== 0x09 && byte !== 0x0a && byte !== 0x0c && byte !== 0x0d) {
115 suspiciousControlBytes += 1
116 }
117 }
118
119 return suspiciousControlBytes / sample.length > 0.01
120}
121
122export function classifyFileMetadata(filePath: string, sample: Uint8Array): FileMetadata {
123 const mediaType = mediaTypeFromMagic(sample) ?? mediaTypeFromExtension(filePath)

Callers 1

classifyFileMetadataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected