zlib.gunzip()方法是Zlib模塊的內置應用程序編程接口,用於解壓縮數據塊。
用法:
zlib.gunzip( buffer, options, callback )
參數:此方法接受上述和以下所述的三個參數:
- buffer:它可以是Buffer,TypedArray,DataView,ArrayBuffer和字符串的類型。
 - options:它是一個可選參數,其中包含zlib選項。
 - callback:它包含回調函數。
 
返回值:解壓縮後,它將返回數據塊。
以下示例說明了Node.js中zlib.gunzip()方法的使用:
範例1:
// Node.js program to demonstrate the      
// gunzip() method 
  
// Including zlib module 
const zlib = require("zlib"); 
  
// Declaring input and assigning 
// it a value string 
var input = "Geek"; 
  
// Calling gzip method 
zlib.gzip(input, (err, buffer) => { 
  
  // Calling gunzip method 
 zlib.gunzip(buffer, (err, buffer) => { 
  
    console.log(buffer.toString('utf8')); 
      
    }); 
 }); 
  
console.log("Data Decompressed...");輸出:
Data Decompressed... Geek
範例2:
// Node.js program to demonstrate the      
// gunzip() method 
  
// Including zlib module 
const zlib = require("zlib"); 
  
// Declaring input and assigning 
// it a value string 
var input = "Geek"; 
  
// Calling gzip method 
zlib.gzip(input, (err, buffer) => { 
  
  // Calling gunzip method 
 zlib.gunzip(buffer, (err, buffer) => { 
  
    console.log(buffer.toString('hex')); 
      
    }); 
 }); 
  
console.log("Data Decompressed...");輸出:
Data Decompressed... 4765656b
參考: https://nodejs.org/api/zlib.html#zlib_zlib_gunzip_buffer_options_callback
相關用法
- 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.gunzip() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
