Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
istextorbinary
Advanced tools
The istextorbinary npm package is used to determine whether a given file or buffer is text or binary. This can be useful in various scenarios such as file processing, content validation, and data handling.
Check if a file is text or binary
This feature allows you to check if a file is text or binary. The `isText` function takes a file path and a callback function. The callback function receives an error (if any) and a boolean indicating whether the file is text.
const istextorbinary = require('istextorbinary');
istextorbinary.isText('example.txt', function(err, result) {
if (err) throw err;
console.log(result ? 'Text' : 'Binary');
});
Check if a buffer is text or binary
This feature allows you to check if a buffer is text or binary. The `isText` function can also take a buffer as an argument. The callback function receives an error (if any) and a boolean indicating whether the buffer is text.
const istextorbinary = require('istextorbinary');
const buffer = Buffer.from('Hello, world!');
istextorbinary.isText(null, buffer, function(err, result) {
if (err) throw err;
console.log(result ? 'Text' : 'Binary');
});
Synchronous check if a file is text or binary
This feature allows you to synchronously check if a file is text or binary. The `isTextSync` function takes a file path and returns a boolean indicating whether the file is text.
const istextorbinary = require('istextorbinary');
const result = istextorbinary.isTextSync('example.txt');
console.log(result ? 'Text' : 'Binary');
Synchronous check if a buffer is text or binary
This feature allows you to synchronously check if a buffer is text or binary. The `isTextSync` function can also take a buffer as an argument and returns a boolean indicating whether the buffer is text.
const istextorbinary = require('istextorbinary');
const buffer = Buffer.from('Hello, world!');
const result = istextorbinary.isTextSync(null, buffer);
console.log(result ? 'Text' : 'Binary');
The file-type package is used to detect the file type of a Buffer/Uint8Array/ArrayBuffer. It can determine the MIME type and extension of a file. Unlike istextorbinary, which focuses on distinguishing between text and binary, file-type provides more detailed information about the file type.
The detect-file-type package is another library for detecting the file type of a buffer or stream. It provides similar functionality to file-type but with a different API. It can identify a wide range of file types, whereas istextorbinary is specifically designed to differentiate between text and binary files.
The binary-parser package is used for parsing binary data in Node.js. It allows you to define a schema for binary data and parse it accordingly. While it doesn't directly compete with istextorbinary, it is useful for working with binary data once you have identified it using istextorbinary.
Determines if a buffer is comprised of text or binary
require('istextorbinary')
npm install --save istextorbinary
// Sync
var result = require('istextorbinary').isTextSync(filename, buffer);
// Async
require('istextorbinary').isText(filename, buffer, function(err, result){
// ...
});
// You can supply text or buffer, or both text and buffer, the more provided, the more accurate the result
// isBinary, and isBinarySync methods also provided
Discover the change history by heading on over to the HISTORY.md
file.
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
These amazing people are maintaining this project:
No sponsors yet! Will you be the first?
These amazing people have contributed code to this project:
Licensed under the incredibly permissive MIT license
Copyright © 2012+ Bevry Pty Ltd us@bevry.me (http://bevry.me)
Copyright © 2011 Benjamin Lupton b@lupton.cc (http://balupton.com)
v1.0.2 2015 January 16
FAQs
Determine if a filename and/or buffer is text or binary. Smarter detection than the other solutions.
The npm package istextorbinary receives a total of 1,351,015 weekly downloads. As such, istextorbinary popularity was classified as popular.
We found that istextorbinary 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.