Skip to content

Extremely fast LZW javascript decompression using WASM

License

Notifications You must be signed in to change notification settings

propellerfactory/fast-lzw

 
 

Repository files navigation

fast-lzw

Extremely fast LZW decompression for JavaScript using WASM extracted from FFmpeg. Can decompress upwards of ~100MB/s.

import { LZW } from 'fast-lzw'
const WORKER_POOL_SIZE = 4

async function decompress(blob) {
  const lzw = new LZW(WORKER_POOL_SIZE)
  const arrayBuffer = await blob.arrayBuffer()
  
  // FastLZW can also take TypedArrays as input, it just
  // gets their ArrayBuffers
  const uint8Arrays = await lzw.decompress([ arrayBuffer ])
  
  return uint8Arrays.map(_ => _.buffer)
}

TIP: For fastest performance, if you have multiple blocks (e.g. from a TIFF), pass them all to LZW.decompress in a single call. Ideally they'd be backed by SharedArrayBuffer(s). FastLZW will not use web workers if instatiated without a WORKER_POOL_SIZE argument.

About

Extremely fast LZW javascript decompression using WASM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 94.5%
  • C++ 2.7%
  • Assembly 1.8%
  • Makefile 0.7%
  • JavaScript 0.2%
  • Objective-C 0.1%