isbinaryfile
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -58,5 +58,5 @@ var fs = require('fs'); | ||
if (total_bytes >= 4 && bytes[0] == 0x25 && bytes[1] == 0x50 && bytes[2] == 0x44 && bytes[3] == 0x46) { | ||
return true; | ||
if (total_bytes >= 5 && bytes.slice(0, 5) == "%PDF-") { | ||
/* PDF. This is binary. */ | ||
return true; | ||
} | ||
@@ -63,0 +63,0 @@ |
{ | ||
"name": "isbinaryfile", | ||
"description": "Detects if a file is binary in Node.js. Similar to Perl's -B.", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"devDependencies": { | ||
@@ -6,0 +6,0 @@ "mocha": "^2.2.4", |
@@ -30,3 +30,3 @@ # isBinaryFile | ||
* `bytes`, an `number` indicating the size of the file. | ||
* `bytes`, a `Buffer` of the file's contents. | ||
* `size`, an optional `number` indicating the file size. | ||
@@ -45,3 +45,3 @@ * `callback`, a `function` for the callback. It has two arguments: | ||
* `bytes`, an `number` indicating the size of the file. | ||
* `bytes`, a `Buffer` of the file's contents. | ||
* `size`, an `number` indicating the file size. | ||
@@ -57,19 +57,21 @@ | ||
if (isBinaryFile(process.argv[2])) | ||
console.log("It is!") | ||
else | ||
console.log("No.") | ||
fs.readFile(process.argv[2], function(err, data) { | ||
fs.lstat(process.argv[2], function(err, stat) { | ||
if (isBinaryFile(data, stat.size)) | ||
console.log("It is!") | ||
else | ||
console.log("No.") | ||
fs.readFile("some_file", function(err, data) { | ||
fs.lstat("some_file", function(err, stat) { | ||
isBinaryFile(data, stat.size, function (err, result) { | ||
if (!err) { | ||
if (result) { | ||
console.log("It is!") | ||
} | ||
else { | ||
console.log("No.") | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
isBinaryFile.sync(process.argv[2]); // true or false | ||
var stat = fs.lstatSync(process.argv[2]); | ||
isBinaryFile.sync(process.argv[2], stat.size); // true or false | ||
isBinaryFile.sync("some_file"); // true or false | ||
var bytes = fs.readFileSync(("some_file")); | ||
var size = fs.lstatSync(("some_file").size; | ||
isBinaryFile.sync(bytes, size); // true or false | ||
``` | ||
@@ -76,0 +78,0 @@ |
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
7356
79