isbinaryfile
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -19,2 +19,3 @@ var fs = require('fs'); | ||
} | ||
// async version has a function instead of a `size` | ||
else if (typeof size === "function") { | ||
@@ -62,11 +63,11 @@ var file = bytes, callback = size; | ||
// UTF-8 detection | ||
if (bytes[i] > 191 && bytes[i] < 224 && i + 1 < total_bytes) { | ||
if (bytes[i] > 193 && bytes[i] < 224 && i + 1 < total_bytes) { | ||
i++; | ||
if (bytes[i] < 192) { | ||
if (bytes[i] > 127 && bytes[i] < 192) { | ||
continue; | ||
} | ||
} | ||
else if (bytes[i] > 223 && bytes[i] < 239 && i + 2 < total_bytes) { | ||
else if (bytes[i] > 223 && bytes[i] < 240 && i + 2 < total_bytes) { | ||
i++; | ||
if (bytes[i] < 192 && bytes[i + 1] < 192) { | ||
if (bytes[i] > 127 && bytes[i] < 192 && bytes[i + 1] > 127 && bytes[i + 1] < 192) { | ||
i++; | ||
@@ -73,0 +74,0 @@ continue; |
{ | ||
"name": "isbinaryfile", | ||
"version" : "2.0.1", | ||
"version" : "2.0.2", | ||
"description": "Detects if a file is binary in Node.js. Similar to Perl's -B.", | ||
@@ -5,0 +5,0 @@ "main" : "./lib/panino.js", |
@@ -30,5 +30,5 @@ isBinaryFile | ||
``` javascript | ||
var isBinaryFileSync = require("isbinaryfile"); | ||
var isBinaryFile = require("isbinaryfile"); | ||
if (isBinaryFileSync(process.argv[2])) | ||
if (isBinaryFile(process.argv[2])) | ||
console.log("It is!") | ||
@@ -48,3 +48,3 @@ else | ||
fs.lstat(process.argv[2], function(err, stat) { | ||
if (isBinaryFileSync(data, stat.size)) | ||
if (isBinaryFile(data, stat.size)) | ||
console.log("It is!") | ||
@@ -60,9 +60,9 @@ else | ||
Previous to version 2.0.0, this program always ran in sync mode. Now, there's | ||
an async option. Simply pass a function as your second parameter, and isBinaryFile | ||
an async option. Simply pass a function as your second parameter, and `isBinaryFile` | ||
will figure the rest out: | ||
``` javascript | ||
var isBinaryFileSync = require("isbinaryfile"); | ||
var isBinaryFile = require("isbinaryfile"); | ||
isBinaryFileSync(process.argv[2], function(err, result) { | ||
isBinaryFile(process.argv[2], function(err, result) { | ||
if (err) return console.error(err); | ||
@@ -69,0 +69,0 @@ |
@@ -56,2 +56,10 @@ "mocha"; | ||
it('should not fail on some UTF8 lua file', function() { | ||
assert(!isBinaryFile("tests/fixtures/07_no.lua")); | ||
var bytes = fs.readFileSync("tests/fixtures/07_no.lua"); | ||
var stat = fs.lstatSync("tests/fixtures/07_no.lua"); | ||
assert(!isBinaryFile(bytes, stat.size)); | ||
}); | ||
it('should not fail with async', function(done) { | ||
@@ -58,0 +66,0 @@ assert.doesNotThrow(function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
83886
14
139