![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
A standalone JavaScript implementation of the Lempel-Ziv-Markov chain (LZMA) compression algorithm
LZMA-JS is a JavaScript implementation of the Lempel-Ziv-Markov chain (LZMA) compression algorithm. The JavaScript, CSS, and HTML is licensed under the MIT license. See LICENSE for more details.
It is based on gwt-lzma, which is a port of the LZMA SDK from Java into JavaScript. The original Java code is licensed under the Apache License 2.0 license.
Live demos can be found here.
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 but not as good; 9 will probably make your browser crash).
my_lzma.compress(string, mode, on_finish(result) {}, on_progress(percent) {});
/// To decompress:
my_lzma.decompress(byte_array, on_finish(result) {}, on_progress(percent) {});
LZMA-JS is available in the npm repository.
$ npm install lzma
and load it with the following code:
var my_lzma = require("lzma").LZMA();
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.
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.
FAQs
A JavaScript implementation of the Lempel-Ziv-Markov (LZMA) chain compression algorithm
The npm package lzma receives a total of 49,707 weekly downloads. As such, lzma popularity was classified as popular.
We found that lzma demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.