$ npm install is-binary
Detects if a file is binary based on its content.

isBinary(content)
Example:
var assert = require('assert');
var fs = require('fs');
var isBinary = require('is-binary');
assert.equal(isBinary(fs.readFileSync('sample.pdf', 'utf8')) === false);
npm test
Main source code extracted from https://github.com/bevry/istextorbinary/, MIT licensed.
Tests inspired by https://github.com/gjtorikian/isBinaryFile, MIT licensed.
MIT http://alessioalex.mit-license.org/
© 2010 - cnpmjs.org x YWFE | Home | YWFE