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.deflateRawSync() module to compress a buffer or a string with Deflate. The
DeflateRawSync() module was introduced in version v0.11.12 of Node.js.
We can implement the
deflateRawSync() module in a program using the following syntax:
deflateRawSync() module accepts two arguments as parameters:
buffer: We use buffers to represent a fixed-length sequence of bytes. In the
deflateRawSync() module, we can include buffers of
options: These are optional objects that we can include in
deflateRawSync() as a parameter.
The function returns the compressed data.
Let’s observe the following implementation to understand how to include a
createDeflateRaw() method into a program code.
const zlib = require('zlib'); var text1 = "Hello this is a string"; var def_raw_sync = zlib.deflateRawSync(text1); console.log(def_raw_sync);
Above is an elementary example of using the
deflateRawSync() module to deflate a string named
text1 and display it on the console log.
View all Courses