New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lzma

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lzma

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

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
65K
decreased by-17.64%
Maintainers
1
Weekly downloads
 
Created
Source

LZMA in a Browser

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

What's New in 2.0

Two things: speed & size.

LZMA-JS 2.0 now minifies to almost half of 1.x and in some cases is 1,000x faster (particularly with high compression).

It is also more modular. The compression and decompression algorithms can be optionally separated to shrink the file size even more.

Here are some file size stats:

FilenameMethod(s)MinifiedGzipped
lzma_worker.jsboth29.3 KB11.2 KB
lzma-c.jscompression22.7 KB9.0 KB
lzma-d.jsdecompression10.5 KB4.4 KB

Demos

Live demos can be found here.

How to Use

First, load the bootstrapping code.

/// In a browser:
<script src="../src/lzma.js"></script>

/// In Node.js:
var LZMA = require("../src/lzma.js").LZMA;

Create the LZMA object.

/// LZMA([optional path])
/// If lzma_worker.js is in the same directory, you don't need to set the path.
/// You should be able to do the first two steps simultaneously in Node.js: var my_lzma = require("../src/lzma.js").LZMA();
var my_lzma = new LZMA("../src/lzma_worker.js");

(De)Compress stuff.

/// To compress:
///NOTE: mode can be 1-9 (1 is fast and pretty good; 9 is very slow and probably a bit better).
///      I suggest keeping mode low, like 1-3.
///      And by the way, 9 is not always the smallest.
my_lzma.compress(string, mode, on_finish(result) {}, on_progress(percent) {});

/// To decompress:
my_lzma.decompress(byte_array, on_finish(result) {}, on_progress(percent) {});

Node.js Installation

LZMA-JS is available in the npm repository.

$ npm install lzma

It can be loaded with the following code:

var my_lzma = require("lzma").LZMA();

Notes

The calls to compress() and decompress() are asynchronous, so you need to supply a callback function if you want to use the (de)compressed data.

If the decompression progress is unable to be calculated, the on_progress() function will be triggered once with the value -1.

LZMA-JS will try to use Web Workers if they are available. If the environment does not support Web Workers, it will just do something else, and it won't pollute the global scope.

LZMA-JS was originally based on gwt-lzma, which is a port of the LZMA SDK from Java into JavaScript.

But I don't want to use Web Workers

If you'd prefer not to bother with Web Workers, you can just include lzma_worker.js directly. For example:

<script src="../src/lzma_worker.js"></script>

That will create a global LZMA object that you can use directly. Like this:

LZMA.compress(string, mode, on_finish(result) {}, on_progress(percent) {});

LZMA.decompress(byte_array, on_finish(result) {}, on_progress(percent) {});

Note that this LZMA variable is an object, not a function.

In Node.js, the Web Worker code is already skipped, so there's no need to do this.

And if you only need to compress or decompress and you're looking to save some bytes, instead of loading lzma_worker.js, you can simply load lzma-c.js (for compression) or lzma-d.js (for decompression).

Of course, you'll want to load the minified versions if you're sending data over the wire.

License

MIT

FAQs

Package last updated on 03 Jan 2015

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