Security News
OpenJS: “XZ Utils Cyberattack Likely Not an Isolated Incident”
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
isbinaryfile
Advanced tools
Weekly downloads
Readme
Detects if a file is binary in Node.js using ✨promises✨. Similar to Perl's -B
switch, in that:
null
byte; if it's found, it's binaryMuch of the logic is pretty much ported from ag.
Note: if the file doesn't exist or is a directory, an error is thrown.
npm install isbinaryfile
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.bytes
- a Buffer
of the file's contents.size
- an optional number
indicating the file size.filepath
- a string
indicating the path to the file.bytes
- a Buffer
of the file's contents.size
- an optional number
indicating the file size.Here's an arbitrary usage:
const isBinaryFile = require("isbinaryfile").isBinaryFile;
const fs = require("fs");
const filename = "fixtures/pdf.pdf";
const data = fs.readFileSync(filename);
const stat = fs.lstatSync(filename);
isBinaryFile(data, stat.size).then((result) => {
if (result) {
console.log("It is binary!")
}
else {
console.log("No it is not.")
}
});
const isBinaryFileSync = require("isbinaryfile").isBinaryFileSync;
const bytes = fs.readFileSync(filename);
const size = fs.lstatSync(filename).size;
console.log(isBinaryFileSync(bytes, size)); // true or false
Run npm install
, then run npm test
.
FAQs
Detects if a file is binary in Node.js. Similar to Perl's -B.
The npm package isbinaryfile receives a total of 4,488,260 weekly downloads. As such, isbinaryfile popularity was classified as popular.
We found that isbinaryfile demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
Company News
Come meet the Socket team at BSidesSF and RSA! We're sponsoring several fun networking events and we would love to see you there.
Security News
OSI is starting a conversation aimed at removing the excuse of the SaaS loophole for companies navigating licensing and the complexities of doing business with open source.