MCPcopy Index your code
hub / github.com/bugy/script-server / is_binary

Function is_binary

src/utils/file_utils.py:392–408  ·  view source on GitHub ↗
(path)

Source from the content-addressed store, hash-verified

390# - based on common binary headers: https://www.garykessler.net/library/file_sigs.html
391# - null bytes (are not very common in text files)
392def is_binary(path):
393 with open(path, 'rb') as f:
394 first_bytes = f.read(1024)
395
396 # Executable and Linking Format executable file (Linux/Unix)
397 if first_bytes.startswith(bytes.fromhex('7F454C46')):
398 return True
399
400 # Windows executable
401 if first_bytes.startswith(bytes.fromhex('4D5A')):
402 return True
403
404 # Files with null bytes are usually binary (except rare UTF-16 cases)
405 if b'\x00\x00' in first_bytes:
406 return True
407
408 return False
409
410
411def is_broken_symlink(file_path):

Callers

nothing calls this directly

Calls 1

readMethod · 0.80

Tested by

no test coverage detected