MCPcopy Index your code
hub / github.com/anomalyco/opencode / isBinaryFile

Function isBinaryFile

packages/opencode/src/tool/read.ts:182–227  ·  view source on GitHub ↗
(filepath: string, bytes: Uint8Array)

Source from the content-addressed store, hash-verified

180 })
181
182 const isBinaryFile = (filepath: string, bytes: Uint8Array) => {
183 const ext = path.extname(filepath).toLowerCase()
184 switch (ext) {
185 case ".zip":
186 case ".tar":
187 case ".gz":
188 case ".exe":
189 case ".dll":
190 case ".so":
191 case ".class":
192 case ".jar":
193 case ".war":
194 case ".7z":
195 case ".doc":
196 case ".docx":
197 case ".xls":
198 case ".xlsx":
199 case ".ppt":
200 case ".pptx":
201 case ".odt":
202 case ".ods":
203 case ".odp":
204 case ".bin":
205 case ".dat":
206 case ".obj":
207 case ".o":
208 case ".a":
209 case ".lib":
210 case ".wasm":
211 case ".pyc":
212 case ".pyo":
213 return true
214 }
215
216 if (bytes.length === 0) return false
217
218 let nonPrintableCount = 0
219 for (let i = 0; i < bytes.length; i++) {
220 if (bytes[i] === 0) return true
221 if (bytes[i] < 9 || (bytes[i] > 13 && bytes[i] < 32)) {
222 nonPrintableCount++
223 }
224 }
225
226 return nonPrintableCount / bytes.length > 0.3
227 }
228
229 const run = Effect.fn("ReadTool.execute")(function* (
230 params: Schema.Schema.Type<typeof Parameters>,

Callers 1

read.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected