How to use 'zlib.deflateRawSync()' in Node.js
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.
Syntax
We can implement the deflateRawSync() module in a program using the following syntax:
zlib.deflateRawSync(buffer, options);
The deflateRawSync() module accepts two arguments as parameters:
-
buffer: We use buffers to represent a fixed-length sequence of bytes. In thedeflateRawSync()module, we can include buffers of<TypedArray>,<DataView>,<ArrayBuffer>, and<string>type. -
options: These are optional objects that we can include indeflateRawSync()as a parameter.
The function returns the compressed data.
Code
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);
Explanation
Above is an elementary example of using the deflateRawSync() module to deflate a string named text1 and display it on the console log.
Free Resources