Coder Social home page Coder Social logo

johtso / binaryornot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from binaryornot/binaryornot

0.0 2.0 0.0 395 KB

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

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

PowerShell 13.45% Batchfile 3.03% Python 59.53% JavaScript 23.50% Lua 0.31% Perl 0.18%

binaryornot's Introduction

BinaryOrNot

https://badge.fury.io/py/binaryornot.png https://travis-ci.org/audreyr/binaryornot.png?branch=master Documentation Status

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

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.

Credits

binaryornot's People

Contributors

audreyfeldroy avatar drmaciver avatar hackebrot avatar pombredanne avatar pydanny avatar scop 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.