Node.js | zlib.bytesWritten Property

The zlib.bytesWritten property is an application programming interface of 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.



Below examples illustrate the use of zlib.bytesWritten method in Node.js:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the     
// zlib.bytesWritten Property
  
// Including assert and zlib 
// module
var zlib = require('zlib');
var assert = require('assert');
  
// Input to be written
const input = Buffer.from('0123456789012345678901');
  
// Calling deflate method
zlib.deflate(input, (err, deflatedBuffer) => {
  assert(!err);
  
  // Declaring buffer and numberRead
  var numberRead = 0;
  var buffers = [];
  
  // Creating a zip object
  var stream = zlib.createGzip()
  
    // Data event
    .on('data', function(chunk) {
     buffers.push(chunk);
     numberRead += chunk.length;
    })
  
    // end event
    .on('end', function() {
       
      // Calling bytesWritten property
      console.log(stream.bytesWritten);
       
      })
    .end(deflatedBuffer);
});

chevron_right


Output:

21

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the     
// zlib.bytesWritten property
   
// Including zlib module
var zlib = require('zlib');
   
// Input to be written
const input = Buffer.from('NidhiSingh1352');
   
// Calling deflateRaw method
zlib.deflateRaw(input, (err, buffer) => {
   
  // Creating a Deflate object
  var zlibs = zlib.Deflate()
   
    // Data event
    .on('data', function(chunk) {})
   
    // end event
    .on('end', function() {
   
      // Calling bytesWritten property
      console.log(zlibs.bytesWritten);
   
    })
   .end(buffer);
});

chevron_right


Output:

16

Reference: https://nodejs.org/api/zlib.html#zlib_zlib_byteswritten




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.