JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 258
  • Score
    100M100P100Q93322F
  • License MIT

A JavaScript implementation of the Lempel-Ziv-Markov (LZMA) chain compression algorithm

Package Exports

  • lzma-web
  • lzma-web/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lzma-web) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

lzma-web

Build Status version bundlephobia MIT License

lzma-web is a JavaScript implementation of the Lempel-Ziv-Markov (LZMA) chain compression algorithm.

The codebase is a fork of LZMA-JS written by Nathan Rugg.

Install

yarn add lzma-web

Usage

import LZMA from 'lzma-web'
const lzma = new LZMA()

const str = "Hello World"

const compressed = await lzma.compress(str)

const decompressed = await lzma.decompress(compressed)

console.log(str === decompressed) // -> true

You can also set the compression level on compress via an optional second parameter:

// value ranges from `1` (fastest) to `9` best
const compressed = await lzma.compress("Hello World", 1)

Finally, lzma-web also supports compression progress via callbacks (for large payloads):

const str = "Hello World"

lmza.cb.compress(
  str, 
  9, // compression level must be set when using callback
  (result, error) => { // when the compression finishes or errors
    if (error) throw error
    console.log(results)
  },
  (progressPercentage) => {
    console.log('the current percentage is', progressPercentage)
  },
)

and decompression progress via callbacks:

const byteArray = [/* <array of bytes> */]

lzma.cb.decompress(
  byteArray,
  (result, error) => {
    if (error) throw error
    console.log(results)
  },
  // If the decompression progress is unable to be calculated, the 
  // `on_progress()` function will be triggered once with the value `-1`.
  (progressPercentage) => {
    console.log('the current percentage is', progressPercentage)
  }
)

Typescript

The repo has typescript support. You can view the types in index.d.ts.

Web Workers

If the current browser supports web workers, lzma-web uses them to prevent blocking the main thread.

Each call of new LZMA() will create a new web worker.

In Node.js and unsupported browsers, lzma-web is run in the main thread.

Almost all modern browsers support web workers: https://caniuse.com/webworkers

Demos

Live demos can be found at http://lzma-js.github.io/LZMA-JS/.

Compatibility

lzma-web is compatible with the reference implementation of LZMA, for example, the lzma command.

License

MIT