Socket
Socket
Sign inDemoInstall

isbinaryfile

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isbinaryfile - npm Package Compare versions

Comparing version 0.1.8 to 0.1.9

29

index.js
var fs = require('fs');
module.exports = function(bytes, size) {
var max_bytes = 512;
// Read the file with no encoding for raw buffer access.

@@ -9,12 +11,17 @@ if (size === undefined) {

return false;
bytes = fs.readFileSync(file);
size = fs.statSync(file).size;
}
var descriptor = fs.openSync(file, 'r');
try {
bytes = new Buffer(max_bytes);
size = fs.readSync(descriptor, bytes, 0, bytes.length, 0);
} finally {
fs.closeSync(descriptor);
}
}
if (size == 0)
if (size == 0)
return false;
var suspicious_bytes = 0;
var total_bytes = size > 512 ? 512 : size;
var total_bytes = Math.min(size, max_bytes);
if (size >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) {

@@ -25,3 +32,3 @@ // UTF-8 BOM. This isn't binary.

for (var i = 0; i < total_bytes; i++) {
for (var i = 0; i < total_bytes; i++) {
if (bytes[i] == 0) { // NULL byte--it's binary!

@@ -37,3 +44,3 @@ return true;

}
}
}
else if (bytes[i] > 223 && bytes[i] < 239 && i + 2 < total_bytes) {

@@ -50,3 +57,3 @@ i++;

return true;
}
}
}

@@ -58,4 +65,4 @@ }

}
return false;
}
}
{
"name": "isbinaryfile",
"version" : "0.1.8",
"version" : "0.1.9",
"description": "Detects if a file is binary in Node.js. Similar to Perl's -B.",

@@ -21,2 +21,2 @@ "main" : "./lib/panino.js",

}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc