Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags


How to use 'zlib.createDeflateRaw()' in Node.js

Dian Us Suqlain

Zlib is a built-in module in Node.js that provides compression or decompression properties on texts and buffers in a program.

We use the zlib.createDeflateRaw() module to create a new DeflateRawa module in the Zlib that we use to compress chunk of data. object. The createDeflateRaw() module was added in version v0.5.8 of Node.js.


zlib.createDeflateRaw( options )

The function accepts only a single parameter that specifies the different options of a Zlib object. It returns the created DeflateRaw object.


We can implement the createDeflateRaw() module in the program using the following syntax:

const obj_defraw = zlib.createDeflateRaw(); 

We have to create a new object for this function to use in the future.

Usage of zlib.createDeflateRaw() in a program


To better understand how to implement a createDeflateRaw() method, let’s observe the following example code.

const zlib = require('zlib');

var obj1;
var def_raw1 = zlib.createDeflateRaw(obj1).toString('utf8');

var obj2;
var def_raw2 = zlib.createDeflateRaw(obj2);


console.log("\n", def_raw2);


The above illustration demonstrates two objects that hold no data: obj1 and obj2.

Objects def_raw1 and def_raw2 use these objects to create new objects for DeflateRaw. We have passed these objects as parameters into the createDeflateRaw() method.

The output for def_raw1 displays the object and its type class in utf8 format, whereas def_raw2 returns the JSON type for obj2. All properties of the new object created using def_raw2 are listed in the console log.




Dian Us Suqlain
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring