On 08.09.2013 16:40, Vincent Bernat wrote: > Package: wnpp > Severity: wishlist > Owner: Vincent Bernat <ber...@debian.org> > > * Package name : binaryornot > Version : 0.1.1 > Upstream Author : Audrey Roy <audr...@gmail.com> > * URL : https://github.com/audreyr/binaryornot > * License : BSD > Programming Lang: Python > Description : Ultra-lightweight pure Python package to check if a file > is binary or text. > > This Python package provides a function to check if a file is a text > file or a binary file. It uses the same heuristic as file(1) by > looking at the first 1024 bytes of the file and checks that all > characters are printable. > >
do we need a package for that? it is effectively: with open(filename, 'r') as f: chunk = f.read(1024) textchars = ''.join(map(chr, [7,8,9,10,12,13,27] + range(0x20, 0x100))) bool(chunk.translate(None, textchars)) and only works with utf-8 or ascii encoded files. -- To UNSUBSCRIBE, email to debian-devel-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: http://lists.debian.org/522c91e4.8000...@googlemail.com