What is gunzipSync() in Node.js zlib module?

The zlib module in Node.js provides compression and decompression functionality utilizing Gzip, Deflate/Inflate, and Brotli.

It can be accessed in your program with:

const zlib = require('zlib');

gunzipSync() is a function of the zlib module, which allows decompressing a stream of data.

Syntax

zlib.gunzipSync( buffer, options )

Parameters

  • buffer is the data to be decompressed. It can be of any type, such as Buffer, TypedArray, DataView, ArrayBuffer, or string.

  • options is an optional parameter used to provide options to the zlib classes.

Return value

The gunzipSync() method returns decompressed data.

Example

In the following example, we provide an input string to the gzipSync() method, which compresses the input in line 8. Then, we use the gunzipSync() method in line 11 to recover the original input string.

// Including zlib module
const zlib = require("zlib");
//input declaration
var input = "Educative";
// Calling gzip method to compress data
var compressed = zlib.gzipSync(input);
console.log("Compressed data: ",compressed.toString('utf8'));
// Calling gunzip method
var decompressed = zlib.gunzipSync(compressed);
console.log("Decompressed data: ",decompressed.toString('utf8'));
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved