当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


node.js zlib.bytesWritten用法及代码示例


zlib.bytesWritten属性是zlib模块的应用程序编程接口,用于指定在处理字节(压缩或解压缩,对于派生类而言正确)之前写入引擎的字节数。

用法:

zlib.bytesWritten

返回值:它返回写入引擎的字节数。



以下示例说明了Node.js中zlib.bytesWritten方法的使用:

范例1:

// 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); 
});

输出:

21

范例2:

// 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); 
});

输出:

16

参考: https://nodejs.org/api/zlib.html#zlib_zlib_byteswritten




相关用法


注:本文由纯净天空筛选整理自nidhi1352singh大神的英文原创作品 Node.js | zlib.bytesWritten Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。