Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wasm-brotli

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wasm-brotli

🗜 WebAssembly compiled Brotli library

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
decreased by-37.29%
Maintainers
1
Weekly downloads
 
Created
Source

wasm-brotli

WebAssembly compiled Brotli library.

Installation

npm install -S wasm-brotli

The awesome thing about wasm-brotli is that it does not need to compile or download any prebuilt binaries!

Usage

Because WebAssembly is supported on both Node.js and several browsers, wasm-brotli is super easy to use.

Node.js

An example of compressing something and saving it to a file via Node.js.

import { compress } from 'wasm-brotli';
import { writeFile } from 'fs';
import { promisify } from 'util';

const writeFileAsync = promisify(writeFile);

const content = Buffer.from('Hello, world!', 'utf8');

(async () => {
  try {
    const compressedContent = await compress(content);
    await writeFileAsync('./hello_world.txt.br', compressedContent);
  } catch (err) {
    console.error(err);
  }
})();

Browser

An example of compressing something and downloading it from the browser.

import { compress } from 'wasm-brotli';

const content = new TextEncoder('utf-8').encode('Hello, world!');

(async () => {
  try {
    const compressedContent = await compress(content);

    const file = new File([compressedContent], 'hello_world.txt.br', { type: 'application/brotli' });

    const link = document.createElement('a');
    link.setAttribute('href', URL.createObjectURL(file));
    link.setAttribute('download', file.name);
    link.click();
  } catch (err) {
    console.error(err);
  }
})();

Documentation

compress(data)

  • data <Uint8Array>

Compress data using Brotli compression.

decompress(data)

Decompress data using Brotli decompression.

brotli(method, data)

  • method <BROTLI_COMPRESS> | <BROTLI_DECOMPRESS>
  • data <Uint8Array>

The function that compress and decompress wrap. Pass any of the constants below and data to compress or decompress.

BROTLI_COMPRESS

Constant, reference, for compressing data with brotli.

BROTLI_DECOMPRESS

Constant, reference, for decompressing data with brotli.

Benchmark

Want to see how fast this is? Go to the benchmark directory to see results, instructions on running your own benchmark, and more.

Development

To build wasm-brotli you will need to install Docker, and pull rustlang/rust:nightly. After that all that is needed is to do the following:

  1. Install all dependencies.
npm install
  1. Build the module.
npm run build
  1. Test the module.
npm test

Keywords

FAQs

Package last updated on 22 Dec 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc