zlib.createUnzip()方法是Zlib模塊的內置應用程序編程接口,用於創建新的Unzip對象。
用法:
zlib.createUnzip( options )
參數:此方法接受單個參數選項,這是一個包含zlib選項的可選參數。
返回值:它返回一個新的Unzip對象。
以下示例說明了Node.js中zlib.createUnzip()方法的使用:
範例1:
// Node.js program to demonstrate the      
// createUnzip() method 
  
// Including zlib module 
var zlib = require('zlib'); 
  
// Calling gzip function to compress data 
zlib.gzip('Nidhi Singh', function(err, data) 
 { 
  if (err)  
  {  
    return console.log('err', err); 
  } 
  
  // Calling createUnzip method 
  // to decompress the data again 
  var unzip = zlib.createUnzip(); 
  unzip.write(data); 
  unzip.on('data', function (data) 
   { 
      console.log(data.toString()); 
  }); 
});輸出:
Nidhi Singh
範例2:
// Node.js program to demonstrate the      
// createUnzip() method 
  
// Including zlib module 
var zlib = require('zlib'); 
  
// Calling gzip function to compress data 
zlib.gzip('Nidhi Singh', function(err, data) 
 { 
  if (err)  
  {  
    return console.log('err', err); 
  } 
  
  // Calling createUnzip method 
  // to decompress the data again 
  var unzip = zlib.createUnzip(); 
  unzip.write(data); 
  unzip.on('data', function (data) 
   { 
      console.log(data.toString('hex')); 
  }); 
});輸出:
4e696468692053696e6768
參考: https://nodejs.org/api/zlib.html#zlib_zlib_createunzip_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.createUnzip() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
