Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

istextorbinary

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

istextorbinary

Determines if a buffer is comprised of text or binary

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
increased by11.82%
Maintainers
1
Weekly downloads
 
Created

What is istextorbinary?

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.

What are istextorbinary's main functionalities?

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');

Other packages similar to istextorbinary

Keywords

FAQs

Package last updated on 15 Jan 2015

Did you know?

Socket

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.

Install

Related posts

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