1'use strict'; 2const common = require('../common'); 3const zlib = require('zlib'); 4const { inspect, promisify } = require('util'); 5const assert = require('assert'); 6const emptyBuffer = Buffer.alloc(0); 7 8(async function() { 9 for (const [ compress, decompress, method ] of [ 10 [ zlib.deflateRawSync, zlib.inflateRawSync, 'raw sync' ], 11 [ zlib.deflateSync, zlib.inflateSync, 'deflate sync' ], 12 [ zlib.gzipSync, zlib.gunzipSync, 'gzip sync' ], 13 [ zlib.brotliCompressSync, zlib.brotliDecompressSync, 'br sync' ], 14 [ promisify(zlib.deflateRaw), promisify(zlib.inflateRaw), 'raw' ], 15 [ promisify(zlib.deflate), promisify(zlib.inflate), 'deflate' ], 16 [ promisify(zlib.gzip), promisify(zlib.gunzip), 'gzip' ], 17 [ promisify(zlib.brotliCompress), promisify(zlib.brotliDecompress), 'br' ], 18 ]) { 19 const compressed = await compress(emptyBuffer); 20 const decompressed = await decompress(compressed); 21 assert.deepStrictEqual( 22 emptyBuffer, decompressed, 23 `Expected ${inspect(compressed)} to match ${inspect(decompressed)} ` + 24 `to match for ${method}`); 25 } 26})().then(common.mustCall()); 27