isbinaryfile
Advanced tools
Comparing version 0.1.2 to 0.1.3
15
index.js
var fs = require('fs'); | ||
module.exports = function(bytes, statSize) { | ||
var size = statSize || null; | ||
module.exports = function(bytes, size) { | ||
// Read the file with no encoding for raw buffer access. | ||
if (size === undefined) { | ||
process.exit(1) | ||
bytes = fs.readFileSync(file); | ||
@@ -24,5 +21,4 @@ size = fs.statSync(file).size; | ||
// Disk IO is so slow that it's worthwhile to do this calculation after every suspicious byte. | ||
// This is true even on a 1.6Ghz Atom with an Intel 320 SSD. | ||
if ((suspicious_bytes * 100) / total_bytes > 10) { | ||
// Read at least 32 bytes before making a decision | ||
if (i > 32 && (suspicious_bytes * 100) / total_bytes > 20) { | ||
return true; | ||
@@ -32,3 +28,8 @@ } | ||
} | ||
if ((suspicious_bytes * 100) / total_bytes > 20) { | ||
return true; | ||
} | ||
return false; | ||
} |
{ | ||
"name": "isbinaryfile", | ||
"version" : "0.1.2", | ||
"version" : "0.1.3", | ||
"description": "Detects if a file is binary in Node.js. Similar to Perl's -B.", | ||
@@ -5,0 +5,0 @@ "main" : "./lib/panino.js", |
@@ -10,4 +10,6 @@ isBinaryFile | ||
Please make sure the file exists before calling this function. | ||
It's also pretty much taken from [ag](https://github.com/ggreer/the_silver_searcher). | ||
Note: please make sure the file exists before calling this function. | ||
## Installation | ||
@@ -14,0 +16,0 @@ |
2717
47