Detect binary file by checking for null bytes.
(path: str)
| 22 | # ------------------------------------------------------------------ |
| 23 | |
| 24 | def is_binary(path: str) -> bool: |
| 25 | """Detect binary file by checking for null bytes.""" |
| 26 | try: |
| 27 | with open(path, "rb") as f: |
| 28 | chunk = f.read(_BINARY_PEEK) |
| 29 | return b"\x00" in chunk |
| 30 | except OSError: |
| 31 | return False |
| 32 | |
| 33 | |
| 34 | # ------------------------------------------------------------------ |