isbinaryfile
Advanced tools
Comparing version 2.0.2 to 2.0.3
14
index.js
@@ -8,5 +8,8 @@ var fs = require('fs'); | ||
if (size === undefined) { | ||
var file = bytes, existsSync = fs.existsSync || path.existsSync; | ||
if (!existsSync(file)) | ||
return false; | ||
var file = bytes; | ||
try { | ||
if(!fs.statSync(file).isFile()) return false; | ||
} catch (err) { | ||
// otherwise continue on | ||
} | ||
var descriptor = fs.openSync(file, 'r'); | ||
@@ -23,5 +26,4 @@ try { | ||
var file = bytes, callback = size; | ||
var exists = fs.exists || path.exists; | ||
exists(file, function (exists) { | ||
if (!exists) return callback(null, false); | ||
fs.stat(file, function(err, stat) { | ||
if (err || !stat.isFile()) return callback(null, false); | ||
@@ -28,0 +30,0 @@ fs.open(file, 'r', function(err, descriptor){ |
{ | ||
"name": "isbinaryfile", | ||
"version" : "2.0.2", | ||
"version" : "2.0.3", | ||
"description": "Detects if a file is binary in Node.js. Similar to Perl's -B.", | ||
@@ -5,0 +5,0 @@ "main" : "./lib/panino.js", |
@@ -64,2 +64,14 @@ "mocha"; | ||
it('should fail a directory', function() { | ||
assert(!isBinaryFile("tests/fixtures/08_dir")); | ||
}); | ||
it('should fail a directory with async', function(done) { | ||
isBinaryFile("tests/fixtures/08_dir", function(err, result) { | ||
assert(!err); | ||
assert(!result); | ||
done(); | ||
}); | ||
}); | ||
it('should not fail with async', function(done) { | ||
@@ -66,0 +78,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
84186
15
151