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 3.0.1 to 3.0.2

LICENSE.txt

6

index.js

@@ -58,5 +58,5 @@ var fs = require('fs');

// PDF
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 @@

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