Node.js zlib.inflateSync() 方法
zlib.inflateSync() 方法是 Zlib 模块的内置应用程序编程接口,用于使用 Inflate 解压缩数据块。
句法:
zlib.inflateSync( buffer, options )
参数:此方法接受上面提到的两个参数,如下所述:
- buffer:该参数保存Buffer、TypedArray、DataView、ArrayBuffer、 字符串类型的缓冲区。
- options:此参数保存 zlib 选项值。
返回值:它使用 Inflate 返回数据块。
下面的例子说明了在 Node.js 中zlib.inflateSync() 方法的使用:
示例 1:
// Node.js program to demonstrate the
// zlib.inflateSync() method
// Including zlib module
var zlib = require('zlib');
// Declaring input and assigning
// it a value string
var input = "GeeksforGeeks";
// Calling deflateSync method
var deflated = zlib.deflateSync(input);
// Calling inflateSync method
var inflated = zlib.inflateSync(
new Buffer.from(deflated)).toString();
console.log(inflated);
输出:
GeeksforGeeks
示例 2:
// Node.js program to demonstrate the
// zlib.inflateSync() method
// Including zlib module
var zlib = require('zlib');
// Declaring input and assigning
// it a value string
var input = "GeeksforGeeks";
// Calling deflateSync method
var deflated = zlib.deflateSync(input).toString('hex');
// Calling inflateSync method
var inflated = zlib.inflateSync(new Buffer.from(
deflated, 'hex')).toString('base64');
console.log(inflated);
输出:
R2Vla3Nmb3JHZWVrcw==
参考: https://nodejs.org/api/zlib.html#zlib_zlib_inflatesync_buffer_options