Registry / serialization / zlibjs

zlibjs

JSON →
library0.3.1jsnpmunverified

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 zlibjs
INSTALL
IMPORT
SIG · ZLIBJS
Z
zlibjs
serializationjavascriptv0.3.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Zlib
const Zlib = require('zlibjs/bin/node-zlib.js');
import Zlib from 'zlibjs';
For Node.js, the 'node-zlib.js' entry point is required, and it exports a single 'Zlib' object containing all compression/decompression classes. Browser usage typically involves loading a .min.js file which exposes 'Zlib' globally.
Deflate
const Zlib = require('zlibjs/bin/node-zlib.js'); const compressor = new Zlib.Deflate(plainData);
import { Deflate } from 'zlibjs';
The 'Deflate' class is accessed as a property of the main 'Zlib' object loaded via CommonJS, not as a direct named export from the package.
Inflate
const Zlib = require('zlibjs/bin/node-zlib.js'); const decompressor = new Zlib.Inflate(compressedData);
import { Inflate } from 'zlibjs/bin/node-zlib.js';
Similar to 'Deflate', the 'Inflate' class is a property of the 'Zlib' object and not directly importable via ESM syntax, which is not supported by this package anyway.

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.

import { Buffer } from 'buffer'; const Zlib = require('zlibjs/bin/node-zlib.js'); function stringToByteArray(str: string): Uint8Array { const array = new Uint8Array(str.length); for (let i = 0; i < str.length; ++i) { array[i] = str.charCodeAt(i) & 0xff; } return array; } const originalString = 'Hello, zlib.js! This is a test string to demonstrate compression and decompression capabilities.'; const plainData = stringToByteArray(originalString); console.log('Original data length:', plainData.length); // Compress using ZLIB Deflate const deflate = new Zlib.Deflate(plainData, { compressionType: Zlib.Deflate.CompressionType.DYNAMIC }); const compressed = deflate.compress(); console.log('Compressed data length (Deflate):', compressed.length); // Decompress using ZLIB Inflate const inflate = new Zlib.Inflate(compressed); const decompressed = inflate.decompress(); console.log('Decompressed data length (Inflate):', decompressed.length); const decompressedString = Buffer.from(decompressed).toString('utf8'); console.log('Decompressed string:', decompressedString); if (originalString === decompressedString) { console.log('Compression and decompression successful!'); } else { console.error('Data mismatch after compression/decompression.'); } // GZIP Compression example const gzip = new Zlib.Gzip(plainData, { flags: { fname: true, comment: false, fhcrc: false }, filename: stringToByteArray('test.txt') }); const gzipped = gzip.compress(); console.log('GZIP compressed data length:', gzipped.length); // GZIP Decompression example const gunzip = new Zlib.Gunzip(gzipped); const gunzipped = gunzip.decompress(); console.log('GZIP decompressed data length:', gunzipped.length); const gunzippedString = Buffer.from(gunzipped).toString('utf8'); console.log('GZIP decompressed string:', gunzippedString);
Debug
Known issues
breakingThis package is no longer actively maintained, with the last release in July 2017. It may contain unpatched security vulnerabilities, compatibility issues with newer Node.js versions or browser environments, and lacks modern features or performance optimizations.
fix
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.
affects: >=0.3.1
gotchaThe GZIP implementation in zlib.js is explicitly stated as 'incomplete' in the README, though it claims to be sufficient for 'usual use'. Developers should test thoroughly for edge cases or specific GZIP features they require.
fix
Always validate GZIP compressed output with other tools and consider alternatives if full GZIP specification compliance is critical.
affects: >=0.3.0
gotchaThe package primarily targets CommonJS for Node.js via a specific path ('zlibjs/bin/node-zlib.js') and global 'Zlib' for browsers. It does not provide official ESM exports, requiring manual adaptation for modern module bundlers or native ESM environments.
fix
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.
affects: >=0.3.0
deprecatedThe `lazy` matching parameter in `Zlib.Deflate` options is explicitly marked as deprecated in the README documentation.
fix
Avoid using the `lazy` option and rely on default or other configuration parameters for compression settings.
affects: >=0.3.0
gotchazlib.js uses `Array.<number>` or `Uint8Array` for all input and output data. Incorrectly passing JavaScript strings or other data types will lead to runtime errors or corrupted compression.
fix
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.
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: Zlib.Deflate is not a constructor
The Zlib object was not correctly imported or is not available in the current scope. This typically happens if the CommonJS `require` path is wrong or if using ESM `import` syntax.
fix
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.
ReferenceError: Zlib is not defined
The Zlib object was not imported or included in the environment.
fix
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.
SyntaxError: Cannot use import statement outside a module
Attempting to use ES module `import` syntax in a CommonJS-only Node.js environment or without proper bundler configuration.
fix
This package does not officially support ESM. Use CommonJS `require()` syntax instead: `const Zlib = require('zlibjs/bin/node-zlib.js');`.
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
34 hits · last 30 days
node
28
OpenAI (training)
1
Resources