![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/private_html/node_modules/encoding-sniffer/ |
# encoding-sniffer [](https://github.com/fb55/encoding-sniffer/actions/workflows/nodejs-test.yml)
An implementation of the HTML encoding sniffer algo, with stream support.
This module wraps around [iconv-lite](https://github.com/ashtuchkin/iconv-lite)
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
```bash
npm install encoding-sniffer
```
## Usage
```js
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);
```
## License
This project is licensed under the MIT License. See the [LICENSE](/LICENSE) file
for more information.