GithubHelp home page GithubHelp logo

theodesp / binaryornot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from binaryornot/binaryornot

2.0 2.0 1.0 423 KB

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

License: BSD 3-Clause "New" or "Revised" License

PowerShell 12.47% Batchfile 2.81% Python 62.47% JavaScript 21.79% Lua 0.28% Perl 0.17%

binaryornot's Introduction

BinaryOrNot

image

Documentation Status

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.

Status

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:

Features

Has tests for these file types:

  • Text: .txt, .css, .json, .svg, .js, .lua, .pl, .rst
  • Binary: .png, .gif, .jpg, .tiff, .bmp, .DS_Store, .eot, .otf, .ttf, .woff, .rgb

Has tests for numerous encodings.

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 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.

Builds

Linux (Ubuntu 12.04 LTS Server Edition 64 bit):

image

Windows (Windows Server 2012 R2 (x64)):

image

Credits

binaryornot's People

Contributors

audreyfeldroy avatar drmaciver avatar hackebrot avatar johtso avatar jwilk avatar pombredanne avatar pydanny avatar scop avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.