The zlib.brotliDecompress() method is an inbuilt application programming interface of the Zlib module which is used to decompresses a chunk of data with BrotliCompress.
Syntax:
javascript
Output:
javascript
Output:
zlib.brotliDecompress( buffer, options, callback )Parameters: This method accepts three parameters as mentioned above and described below:
- buffer: It can be of type Buffer, TypedArray, DataView, ArrayBuffer, and string.
- options: It is an optional parameter that holds the zlib options.
- callback: It holds the callback function.
// Node.js program to demonstrate the
// brotliDecompress() method
// Including zlib module
const zlib = require("zlib");
// Declaring input and assigning
// it a value string
var input = "Computer Science";
// Calling brotliCompress method
zlib.brotliCompress(input, (err, buffer) => {
// Calling brotliDecompress
zlib.brotliDecompress(buffer, (err, buffer) => {
console.log(buffer.toString('base64'));
});
});
Q29tcHV0ZXIgU2NpZW5jZQ==Example 2:
// Node.js program to demonstrate the
// brotliDecompress() method
// Including zlib module
const zlib = require("zlib");
// Declaring input and assigning
// it a value string
var input = "Computer Science";
// Calling brotliCompress method
zlib.brotliCompress(input, (err, buffer) => {
// Calling brotliDecompress
zlib.brotliDecompress(buffer, (err, buffer) => {
console.log(buffer.toString('bas64'));
});
});
buffer.js:631 throw new ERR_UNKNOWN_ENCODING(encoding); ^
TypeError [ERR_UNKNOWN_ENCODING]: Unknown encoding: bas64
at stringSlice (buffer.js:631:9) at Buffer.toString (buffer.js:667:10)
at BrotliDecompress.zlib.brotliDecompress [as cb]
(/home/runner/BeautifulMiserlySourcecode/index.js:18:28)
at BrotliDecompress.zlibBufferOnEnd (zlib.js:133:10)
at BrotliDecompress.emit (events.js:203:15)
at BrotliDecompress.EventEmitter.emit (domain.js:448:20)
at endReadableNT (_stream_readable.js:1143:12)
at process._tickCallback (internal/process/next_tick.js:63:19)?
Here, an error occurs while encoding so, an error is thrown.
Reference: https://nodejs.org/api/zlib.html#zlib_zlib_brotlidecompress_buffer_options_callback