Ultra-lightweight pure Python package to check if a file is binary or text.
.. image:: https://img.shields.io/pypi/v/binaryornot.svg?style=flat :target: https://pypi.python.org/pypi/binaryornot
.. image:: https://readthedocs.org/projects/binaryornot/badge/?version=latest :target: http://binaryornot.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status
.. image:: https://pyup.io/repos/github/audreyr/binaryornot/shield.svg :target: https://pyup.io/repos/github/audreyr/binaryornot/ :alt: Updates
Ultra-lightweight pure Python package to guess whether a file is binary or text,
using a heuristic similar to Perl's pp_fttext
and its analysis by @eliben.
It works, and people are using this package in various places. But it doesn't cover all edge cases yet.
The code could be improved. Pull requests welcome! As of now, it is based on these snippets, but that may change:
Has tests for these file types:
Has tests for numerous encodings.
You may be thinking, "I can write this in 2 lines of code?!"
It's actually not that easy. Here's a great article about how Perl's heuristic to guess file types works: http://eli.thegreenplace.net/2011/10/19/perls-guess-if-file-is-text-or-binary-implemented-in-python/
And that's just where we started. Over time, we've found more edge cases and our heuristic has gotten more complex.
Also, this package saves you from having to write and thoroughly test your code with all sorts of weird file types and encodings, cross-platform.
Linux (Ubuntu 12.04 LTS Server Edition 64 bit):
.. image:: https://img.shields.io/travis/audreyr/binaryornot/master.svg :target: https://travis-ci.org/audreyr/binaryornot
Windows (Windows Server 2012 R2 (x64)):
.. image:: https://img.shields.io/appveyor/ci/audreyr/binaryornot/master.svg :target: https://ci.appveyor.com/project/audreyr/binaryornot
pp_fttext
that checks for textiness: https://github.com/Perl/perl5/blob/v5.23.1/pp_sys.c#L3527-L35870.4.4 (2017-04-13)
* Notify users for file i/o issues. Thanks @lukehinds!
0.4.3 (2017-04-13)
0.4.2 (2017-04-12)
* Restricted chardet to anything under 3.0 due to https://github.com/chardet/chardet/issues/113
* Added pyup badge
* Added utilities for pushing new versions up
0.4.0 (2015-08-21)
@pombredanne
_.@pydanny
_.@asmeurer
_ @pombredanne
_ @audreyr
_.@DRMacIver
_.@DRMacIver
_.@hackebrot
_.@hackebrot
_.@hackebrot
_ @pydanny
_.@DRMacIver
_... _@pombredanne
: https://github.com/pombredanne
.. _@pydanny
: https://github.com/pydanny
.. _@asmeurer
: https://github.com/asmeurer
.. _@audreyr
: https://github.com/audreyr
.. _@DRMacIver
: https://github.com/DRMacIver
.. _@hackebrot
: https://github.com/hackebrot
0.3.0 (2014-05-05)
* Include tests, docs in source package. (#6) Thanks `@vincentbernat`_.
* Drop unnecessary shebangs and executable bits. (#8) Thanks `@scop`_.
* Generate string of printable extended ASCII bytes only once. (#7) Thanks `@scop`_.
* Make number of bytes to read parametrizable. (#7) Thanks `@scop`_.
.. _`@vincentbernat`: https://github.com/vincentbernat
.. _`@scop`: https://github.com/scop
0.2.0 (2013-09-22)
@ncoghlan
_... _@ncoghlan
: https://github.com/ncoghlan
0.1.1 (2013-08-17)
* Tests pass under Python 2.6, 2.7, 3.3, PyPy.
0.1.0 (2013-08-17)