Socket
Socket
Sign inDemoInstall

brotli

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    brotli

A port of the Brotli compression algorithm as used in WOFF2


Version published
Weekly downloads
2.7M
increased by4.91%
Maintainers
1
Install size
2.20 MB
Created
Weekly downloads
 

Package description

What is brotli?

The brotli npm package is a compression library that implements the Brotli compression algorithm. It provides methods for compressing and decompressing data using Brotli in Node.js applications.

What are brotli's main functionalities?

Compression

This feature allows you to compress data using the Brotli algorithm. The code sample demonstrates how to read a file, compress its contents, and then write the compressed data to a new file with a .br extension.

const brotli = require('brotli');
const fs = require('fs');

const input = fs.readFileSync('input.txt');
const compressed = brotli.compress(input);
fs.writeFileSync('input.txt.br', compressed);

Decompression

This feature allows you to decompress data that was previously compressed with the Brotli algorithm. The code sample shows how to read a compressed file, decompress its contents, and then write the decompressed data to a new file.

const brotli = require('brotli');
const fs = require('fs');

const compressed = fs.readFileSync('input.txt.br');
const decompressed = brotli.decompress(compressed);
fs.writeFileSync('output.txt', decompressed);

Other packages similar to brotli

Readme

Source

Brotli.js

Brotli.js is port of the Brotli compression algorithm (as used in the WOFF2 font format) to JavaScript using Emscripten. The original C++ source code can be found here and in this repo as a submodule.

Installation and usage

Install using npm.

npm install brotli

If you want to use brotli in the browser, you should use Browserify to build it.

In node, or in browserify, you can load brotli in the standard way:

var brotli = require('brotli');

API

brotli.decode(buffer, outSize)

Decompresses the given buffer to produce the original input to the compressor. This function works best if you know the original size of the data (e.g. to decompressed size). Inside a WOFF2 file, this is encoded as a field in the header of the binary file. If you don't know the size of the input, don't include the outSize argument and the function will guess a size that it thinks will be big enough. If it guessed too small, or there was a decoding error, null is returned.

// decode a buffer where the output size is known
brotli.decode(compressedData, uncompressedLength);

// decode a buffer where the output size is not known
brotli.decode(fs.readFileSync('compressed.bin'));

brotli.encode(buffer, isText = false)

Compresses the given buffer. Pass true as the second argument if the input buffer is text data. Pass false or nothing if it is binary. This function is known to be quite slow.

// encode a buffer of binary data
brotli.encode(fs.readFileSync('myfile.bin'));

// encode some text data
brotli.encode(fs.readFileSync('myfile.bin'), true);

License

MIT

Keywords

FAQs

Last updated on 29 Sep 2014

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc