Skip to main content

Ultra-lightweight pure Python package to check if a file is binary or text.

Project description

https://badge.fury.io/py/binaryornot.png https://travis-ci.org/audreyr/binaryornot.png?branch=master https://pypip.in/d/binaryornot/badge.png

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.

Status

It works, and I’m 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:

Features

Has tests for these file types:

  • Text: .css, .json, .txt, .svg

  • Binary: .eot, .otf, ttf, .woff, .png, .jpg, .tiff, .bmp

Why?

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 perldoc’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/

Also, this package saves you from having to write and thoroughly test those 2 lines of code with all sorts of weird file types, cross-platform.

Credits

History

0.2.0 (2013-09-22)

  • Complete rewrite of everything.

0.1.1 (2013-08-17)

  • Tests pass under Python 2.6, 2.7, 3.3, PyPy.

0.1.0 (2013-08-17)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binaryornot-0.2.0.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file binaryornot-0.2.0.tar.gz.

File metadata

  • Download URL: binaryornot-0.2.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for binaryornot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 efae90facfcffc9141e2128d1e378132356d969ce46518c8ff3983cce9846fcc
MD5 ecbb411e281f3d922112c5d91f575e06
BLAKE2b-256 e496e1315c402347ea734bcce81fc7293816288cc9bf0ad226d195a05cc06962

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page