Helper utilities used by BinaryOrNot.
- filename – File to open and get the first little chunk of.
- length – Number of bytes to read, default 1024.
Starting chunk of bytes.
Uses a simplified version of the Perl detection algorithm, based roughly on Eli Bendersky’s translation to Python: http://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python/
This is biased slightly more in favour of deeming files as text files than the Perl algorithm, since all ASCII compatible character sets are accepted as text, not just utf-8.
Parameters: bytes – A chunk of bytes to check. Returns: True if appears to be a binary, otherwise False.
Print a string as hex bytes.