istextorbinary

  • Version 6.0.0
  • Published
  • 71.3 kB
  • 2 dependencies
  • MIT license

Install

npm i istextorbinary
yarn add istextorbinary
pnpm add istextorbinary

Overview

Determine if a filename and/or buffer is text or binary. Smarter detection than the other solutions.

Index

Functions

function getEncoding

getEncoding: (
buffer: Buffer | null,
opts?: EncodingOpts
) => 'utf8' | 'binary' | null;
  • Get the encoding of a buffer. Checks the start, middle, and end of the buffer for characters that are unrecognized within UTF8 encoding. History has shown that inspection at all three locations is necessary.

    Returns

    Will be null if buffer was not provided. Otherwise will be either 'utf8' or 'binary'

function isBinary

isBinary: (filename?: string | null, buffer?: Buffer | null) => boolean;
  • Determine if the filename and/or buffer is binary. Determined by extension checks first (if filename is available), otherwise if unknown extension or no filename, will perform a slower buffer encoding detection. This order is done, as extension checks are quicker, and also because encoding checks cannot guarantee accuracy for chars between utf8 and utf16. The extension checks are performed using the resources https://github.com/bevry/textextensions and https://github.com/bevry/binaryextensions

    Parameter filename

    The filename for the file/buffer if available

    Parameter buffer

    The buffer for the file if available

    Returns

    Will be null if neither filename nor buffer were provided. Otherwise will be a boolean value with the detection result.

function isText

isText: (filename?: string | null, buffer?: Buffer | null) => boolean | null;
  • Determine if the filename and/or buffer is text. Determined by extension checks first (if filename is available), otherwise if unknown extension or no filename, will perform a slower buffer encoding detection. This order is done, as extension checks are quicker, and also because encoding checks cannot guarantee accuracy for chars between utf8 and utf16. The extension checks are performed using the resources https://github.com/bevry/textextensions and https://github.com/bevry/binaryextensions

    Parameter filename

    The filename for the file/buffer if available

    Parameter buffer

    The buffer for the file if available

    Returns

    Will be null if neither filename nor buffer were provided. Otherwise will be a boolean value with the detection result.

Interfaces

interface EncodingOpts

interface EncodingOpts {}

    property chunkBegin

    chunkBegin?: number;
    • If not provided, will check the start, beginning, and end

    property chunkLength

    chunkLength?: number;
    • Defaults to 24

    Package Files (1)

    Dependencies (2)

    Dev Dependencies (18)

    Peer Dependencies (0)

    No peer dependencies.

    Badge

    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/istextorbinary.

    • Markdown
      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/istextorbinary)
    • HTML
      <a href="https://www.jsdocs.io/package/istextorbinary"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>