Function which determines if a given file is binary.
Test is based on the following algorithm (similar to that implemented within Perl):
- Empty files are considered text.
- If not empty, read up to 512 bytes as a buffer. File will be binary if:
- Null byte is encountered.
- More than 30% of the buffer consists of "non text" characters.
- Otherwise, file is text.
one of the strangest comments I've read for a while. 😄