encoding-sniffer
Implementation of the HTML encoding sniffer algo, with stream support
Last updated 8 months ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install encoding-sniffer 
SYNC missed versions from official npm registry.

encoding-sniffer Node.js CI

An implementation of the HTML Standard's encoding sniffing algorithm, with stream support.

This module wraps around @exodus/bytes to make decoding buffers and streams incredibly easy.

Features

  • Support for streams
  • Support for XML encoding types, including UTF-16 prefixes and <?xml encoding="...">
  • Allows decoding streams and buffers with a single function call

Installation

npm install encoding-sniffer

Usage

import { DecodeStream, getEncoding, decodeBuffer } from "encoding-sniffer";

/**
 * All functions accept an optional options object.
 *
 * Available options are (with default values):
 */
const options = {
    /**
     * The maximum number of bytes to sniff. Defaults to `1024`.
     */
    maxBytes: 1024,
    /**
     * The encoding specified by the user. If set, this will only be overridden
     * by a Byte Order Mark (BOM).
     */
    userEncoding: undefined,
    /**
     * The encoding specified by the transport layer. If set, this will only be
     * overridden by a Byte Order Mark (BOM) or the user encoding.
     */
    transportLayerEncodingLabel: undefined,
    /**
     * The default encoding to use, if no encoding can be detected.
     *
     * Defaults to `"windows-1252"`.
     */
    defaultEncoding: "windows-1252",
};

// Use the `DecodeStream` transform stream to automatically decode
// the contents of a stream as they are read
const decodeStream = new DecodeStream(options);

// Or, use the `getEncoding` function to detect the encoding of a buffer
const encoding = getEncoding(buffer, options);

// Use the `decodeBuffer` function to decode the contents of a buffer
const decodedBuffer = decodeBuffer(buffer, options);

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Current Tags

  • 1.0.2                                ...           latest (8 months ago)

9 Versions

  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           8 months ago
  • 1.0.0                                ...           8 months ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.2                                ...           4 years ago
  • 0.0.1                                ...           4 years ago
  • 0.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Total 62
Today 0
This Week 1
This Month 27
Last Day 0
Last Week 15
Last Month 35
Dependencies (1)
Dev Dependencies (9)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE