Last active
August 29, 2015 14:21
-
-
Save ryonsherman/9432f43786b09d1f1a9e to your computer and use it in GitHub Desktop.
Determine whether a file is binary or text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
def fileIsBinary(path): | |
text = bytearray([7, 8, 9, 10, 12, 13, 27]) + bytearray(range(0x20, 0x100)) | |
return bool(open(path, 'rb').read(1024).translate(None, text)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example