Node.js zlib.bytesWritten Property
Last Updated :
03 Apr, 2023
The zlib.bytesWritten property is an application programming interface of the zlib module which is used to specify the number of bytes written to the engine before the bytes are processed (compressed or decompressed, as proper for the derived class).
Syntax:
zlib.bytesWritten
Return Value: It returns the number of bytes written to the engine.
The below examples illustrate the use of zlib.bytesWritten method in Node.js:
Example 1:
javascript
const zlib = require( 'zlib' );
const assert = require( 'assert' );
const input = Buffer.from( '0123456789012345678901' );
zlib.deflate(input, (err, deflatedBuffer) => {
assert(!err);
let numberRead = 0;
let buffers = [];
const stream = zlib.createGzip()
.on( 'data' , function (chunk) {
buffers.push(chunk);
numberRead += chunk.length;
})
.on( 'end' , function () {
console.log(stream.bytesWritten);
})
.end(deflatedBuffer);
});
|
Output:
21
Example 2:
javascript
const zlib = require( 'zlib' );
const input = Buffer.from( 'NidhiSingh1352' );
zlib.deflateRaw(input, (err, buffer) => {
const zlibs = zlib.Deflate()
.on( 'data' , function (chunk) { })
.on( 'end' , function () {
console.log(zlibs.bytesWritten);
})
.end(buffer);
});
|
Output:
16
Reference: https://nodejs.org/api/zlib.html#zlib_zlib_byteswritten
Share your thoughts in the comments
Please Login to comment...