zlib.js is a pure JavaScript implementation of various data compression algorithms, including ZLIB (RFC1950), DEFLATE (RFC1951), GZIP (RFC1952), and PKZIP. The current stable version is 0.3.1, released in July 2017. As a pure JavaScript solution, it provides cross-environment compatibility (Node.js and browser) without native dependencies. Its key differentiator lies in offering fine-grained control over different compression types and options directly within JavaScript, contrasting with environments like Node.js that provide native bindings to zlib. However, the package has not seen updates since 2017, suggesting it is no longer actively maintained and may lack modern features, performance optimizations, or security patches compared to contemporary alternatives.
npm install zlibjsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates ZLIB compression and decompression, along with a basic GZIP compression example, using the Node.js entry point of zlib.js. It highlights how to initialize Deflate, Inflate, Gzip, and Gunzip classes, handle data as Uint8Array, and convert between strings and byte arrays.
Consider migrating to actively maintained libraries like `pako` for browser/universal use or Node.js's built-in `zlib` module for server-side applications, which offer better performance, security, and modern APIs.
Always validate GZIP compressed output with other tools and consider alternatives if full GZIP specification compliance is critical.
Use CommonJS `require()` syntax directly. For browser environments, ensure the correct minified script is loaded globally. Modern bundlers might require specific configurations (e.g., aliasing or CJS compatibility loaders) to integrate it.
Avoid using the `lazy` option and rely on default or other configuration parameters for compression settings.
Always convert string data to `Uint8Array` before passing it to compression functions, and convert decompressed `Uint8Array` back to strings as needed. Helper functions like `stringToByteArray` are often necessary.
Ensure you are using `const Zlib = require('zlibjs/bin/node-zlib.js');` for Node.js environments. For browsers, ensure `zlib_and_gzip.min.js` or similar files are loaded globally before usage.In Node.js, ensure `require('zlibjs/bin/node-zlib.js')` is called and assigned to a `Zlib` variable. In browsers, verify that the appropriate `zlib.js` distribution file is included via a `<script>` tag before your application code.This package does not officially support ESM. Use CommonJS `require()` syntax instead: `const Zlib = require('zlibjs/bin/node-zlib.js');`.No dependency data recorded yet.