Socket
Socket
Sign inDemoInstall

brotli

Package Overview
Dependencies
1
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
Maintainers
1
Weekly downloads
2,535,066
decreased by-8.06%

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. The decompressor is hand ported, and the compressor is ported with Emscripten. The original C++ source code can be found here.

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

You can also require just the decompress function or just the compress function, which is useful for browserify builds. For example, here's how you'd require just the decompress function.

var decompress = require('brotli/decompress');

API

brotli.decompress(buffer, [outSize])

Decompresses the given buffer to produce the original input to the compressor. The outSize parameter is optional, and will be computed by the decompressor if not provided. Inside a WOFF2 file, this can be computed from the WOFF2 directory.

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

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

brotli.compress(buffer, isText = false)

Compresses the given buffer. Pass optional parameters as the second argument.

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

// encode some data with options (default options shown)
brotli.compress(fs.readFileSync('myfile.bin'), {
  mode: 0, // 0 = generic, 1 = text, 2 = font (WOFF2)
  quality: 11, // 0 - 11
  lgwin: 22 // window size
});

License

MIT

Keywords

FAQs

Last updated on 08 Jun 2022

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