New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lzw-lite

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

lzw-lite

A tiny, text-based LZW implementation for JS with built-in optimizations. Useful for IndexDB storage with minimal overhead.

latest
Source
npmnpm
Version
1.0.5
Version published
Weekly downloads
35
-14.63%
Maintainers
1
Weekly downloads
 
Created
Source

LZW Lite

A tiny, text-based LZW implementation for JS with built-in optimizations. Useful for IndexDB storage with minimal overhead.

Why you should use lzw-lite

  • ✅ Uses native TextEncoder/TextDecoder and Uint8Arrays which makes it input-agnostic
  • ✅ Full support for unicode/emoji character range
  • ✅ Utilizes a dynamic bit size optimization to squeeze out a few extra bytes

Getting started

npm i lzw-lite
import {compress, decompress} from "lzw-lite"; 

/** Convert string -> Uint8Array to store in IndexDB */
const mystringToCompress = "insert string here"; 
const compressed: Uint8Array = compress(mystringToCompress);

/** Convert Uint8Array -> string to get original value back */
const myOriginalString = decompress(compressed);

A note on compilation targets

For optimal bundle size, lzw-lite is compiled with target ESNext. The package.json exposes both a type module (preffered) and type UMD export. If your target does not support the given ESM features, you will have to recompile/polyfill with your own bundler.

Missing Optimizations/Problems

  • Dictionary resets for large files
  • For large files (~1GB+), there is a chance that the dictionary will exceed 2 ** 31 which will cause an overflow in bit-shift operations.
  • TLDR: do not use the library with large files as it has not been optimized for this use-case.

Note on future use

Eventually, the CompressionStream and DecompressionStream API from Google will hopefully land in most browsers which will provide a native GZIP library in the browser.

For now, the API's are only avaliable on latest Chrome versions and there are no plans from other browsers (so far) to support them.

Other, similar libraries

https://github.com/pieroxy/lz-string/blob/master/libs/lz-string.min.js (4.61 KB min)

Keywords

LZW

FAQs

Package last updated on 09 Apr 2021

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