Compression with zlib
zlib compresses and decompresses data with gzip or deflate. Sync versions are fine for small data.
Example
const zlib = require('node:zlib');
const input = 'hello '.repeat(100);
const packed = zlib.gzipSync(input);
console.log(input.length, packed.length < input.length);
console.log(zlib.gunzipSync(packed).toString() === input);Result
600 true true
Exercise
Compress with gzip.
zlib.Sync(data)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.