Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

node.js

How to use 'zlib.deflateRawSync()' 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.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 the deflateRawSync() module, we can include buffers of <TypedArray>, <DataView>, <ArrayBuffer>, and <string> type.

  • options: These are optional objects that we can include in deflateRawSync() as a parameter.

The function returns the compressed data.

Arguments in zlib.deflateRawSync()

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.

RELATED TAGS

node.js

CONTRIBUTOR

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

View all Courses

Keep Exploring