zlib.createGunzip()方法是Zlib模塊的內置應用程序編程接口,用於創建新的Gunzip對象。
用法:
zlib.createGunzip( options )
參數:此方法接受單個參數選項,這是一個包含zlib選項的可選參數。
返回值:它返回一個新的Gunzip對象。
以下示例說明了Node.js中zlib.createGunzip()方法的使用:
範例1:
// Node.js program to demonstrate the      
// createGunzip() method 
  
// Including zlib module 
var zlib = require('zlib'); 
  
// Calling gzip function to compress data 
zlib.gzip('GeeksforGeeks', function(err, data) { 
  if (err) {  
    return console.log('err', err); 
  } 
  
  // Calling createGunzip method 
  // to decompress the data again 
  var gunzip = zlib.createGunzip(); 
  gunzip.write(data); 
  gunzip.on('data', function (data) 
   { 
      console.log(data.toString()); 
  }); 
});輸出:
GeeksforGeeks
範例2:
// Node.js program to demonstrate the      
// createGunzip() method 
  
// Including zlib module 
var zlib = require('zlib'); 
  
// Calling gzip function to compress data 
zlib.gzip('GfG', function(err, data) { 
  if (err) {  
    return console.log('err', err); 
  } 
  
  // Calling createGunzip method 
  // to decompress the data again 
  var gunzip = zlib.createGunzip(); 
  gunzip.write(data); 
  gunzip.on('data', function (data) 
   { 
      // Encoding the data 
      console.log(data.toString('hex')); 
  }); 
});輸出:
476647
參考: https://nodejs.org/api/zlib.html#zlib_zlib_creategunzip_options
相關用法
- Node.js GM blur()用法及代碼示例
 - Node.js GM drawRectangle()用法及代碼示例
 - Node.js GM sharpen()用法及代碼示例
 - Node.js GM drawPolyline()用法及代碼示例
 - Node.js GM drawEllipse()用法及代碼示例
 - Node.js GM drawCircle()用法及代碼示例
 - Node.js GM drawPolygon()用法及代碼示例
 
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Node.js | zlib.createGunzip() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
