isbinaryfile
Advanced tools
Comparing version 3.0.3 to 4.0.0-rc1
@@ -1,2 +0,2 @@ | ||
Copyright (c) 2017 Garen J. Torikian | ||
Copyright (c) 2019 Garen J. Torikian | ||
@@ -3,0 +3,0 @@ MIT License |
{ | ||
"name": "isbinaryfile", | ||
"description": "Detects if a file is binary in Node.js. Similar to Perl's -B.", | ||
"version": "3.0.3", | ||
"dependencies": { | ||
"buffer-alloc": "^1.2.0" | ||
}, | ||
"version": "4.0.0-rc1", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^2.2.4", | ||
"grunt": "~0.4.1", | ||
"grunt-release": "~0.6.0", | ||
"grunt-exec": "0.4.3", | ||
"grunt-cli": "~0.1.13" | ||
"@types/jest": "^23.3.12", | ||
"@types/node": "^10.12.18", | ||
"jest": "^23.6.0", | ||
"prettier": "^1.15.3", | ||
"ts-jest": "^23.10.5", | ||
"tslint": "^5.12.0", | ||
"tslint-config-prettier": "^1.17.0", | ||
"typescript": "^3.2.2" | ||
}, | ||
"engines": { | ||
"node": ">=0.6.0" | ||
"node": ">= 8.0.0" | ||
}, | ||
"files": [ | ||
"index.js" | ||
"lib/**/*" | ||
], | ||
"license": "MIT", | ||
"main": "./index.js", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"maintainers": [ | ||
@@ -34,4 +36,13 @@ { | ||
"scripts": { | ||
"test": "mocha" | ||
"build": "tsc", | ||
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"", | ||
"lint": "tslint -p tsconfig.json", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"preversion": "npm run lint", | ||
"version": "npm run format && git add -A src", | ||
"postversion": "git push && git push --tags", | ||
"test": "jest --config jestconfig.json", | ||
"watch": "tsc -w" | ||
} | ||
} |
# isBinaryFile | ||
Detects if a file is binary in Node.js. Similar to [Perl's `-B` switch](http://stackoverflow.com/questions/899206/how-does-perl-know-a-file-is-binary), in that: | ||
Detects if a file is binary in Node.js using ✨promises✨. Similar to [Perl's `-B` switch](http://stackoverflow.com/questions/899206/how-does-perl-know-a-file-is-binary), in that: | ||
- it reads the first few thousand bytes of a file | ||
@@ -10,3 +10,3 @@ - checks for a `null` byte; if it's found, it's binary | ||
Note: if the file doesn't exist, is a directory, or is empty, the function returns `false`. | ||
Note: if the file doesn't exist or is a directory, an error is thrown. | ||
@@ -21,55 +21,42 @@ ## Installation | ||
### isBinaryFile(filepath, callback) | ||
Returns `Promise<boolean>` (or just `boolean` for `*Sync`). `true` if the file is binary, `false` otherwise. | ||
* `filepath`, a `string` indicating the path to the file. | ||
* `callback`, a `function` for the callback. It has two arguments: | ||
- `err`, the typical Node.js error argument | ||
- `result`, a `boolean` of `true` or `false`, depending on if the file is binary | ||
### isBinaryFile(filepath) | ||
* `filepath` - a `string` indicating the path to the file. | ||
### isBinaryFile(bytes, size, callback) | ||
### isBinaryFile(bytes[, size]) | ||
* `bytes`, a `Buffer` of the file's contents. | ||
* `size`, an optional `number` indicating the file size. | ||
* `callback`, a `function` for the callback. It has two arguments: | ||
- `err`, the typical Node.js error argument | ||
- `result`, a `boolean` of `true` or `false`, depending on if the file is binary | ||
* `bytes` - a `Buffer` of the file's contents. | ||
* `size` - an optional `number` indicating the file size. | ||
### isBinaryFileSync(filepath) | ||
### isBinaryFile.sync(filepath) | ||
* `filepath` - a `string` indicating the path to the file. | ||
* `filepath`, a `string` indicating the path to the file. | ||
### isBinaryFileSync(bytes[, size]) | ||
### isBinaryFile.sync(bytes, size) | ||
* `bytes` - a `Buffer` of the file's contents. | ||
* `size` - an optional `number` indicating the file size. | ||
* `bytes`, a `Buffer` of the file's contents. | ||
* `size`, an `number` indicating the file size. | ||
Returns a `boolean` of `true` or `false`, depending on if the file is binary. | ||
### Examples | ||
```javascript | ||
var isBinaryFile = require("isbinaryfile"); | ||
const isBinaryFile = require("isbinaryfile").isBinaryFile; | ||
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.") | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
const data = await fs.readFile("some_file"); | ||
const stat = await fs.lstat("some_file"); | ||
isBinaryFile.sync("some_file"); // true or false | ||
var bytes = fs.readFileSync(("some_file")); | ||
var size = fs.lstatSync(("some_file").size; | ||
isBinaryFile(data, stat.size).then((result) => { | ||
if (result) { | ||
console.log("It is binary!") | ||
} | ||
else { | ||
console.log("No it is not.") | ||
} | ||
})); | ||
let bytes = fs.readFileSync(("some_file")); | ||
let size = fs.lstatSync(("some_file").size; | ||
isBinaryFile.sync(bytes, size); // true or false | ||
@@ -80,2 +67,2 @@ ``` | ||
Run `npm install` to install `mocha`, then run `npm test`. | ||
Run `npm install`, then run `npm test`. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
9609
0
5
142
8
2
66
1
- Removedbuffer-alloc@^1.2.0
- Removedbuffer-alloc@1.2.0(transitive)
- Removedbuffer-alloc-unsafe@1.1.0(transitive)
- Removedbuffer-fill@1.0.0(transitive)