it("should compress with 'gzip'", () => { const mw = Middleware({ method: "gzip", threshold: 0 }); mw.created(broker); const meta = {}; const next = jest.fn(() => Promise.resolve()); const send = mw.transporterSend.call(broker, next); return send("topic", Buffer.from("uncompressed data"), meta).catch(protectReject).then(() => { expect(next).toHaveBeenCalledTimes(1); expect(next).toHaveBeenCalledWith("topic", expect.any(Buffer), meta); expect(next.mock.calls[0][1]).toEqual(Buffer.concat([COMPRESSED_FLAG, zlib.gzipSync(Buffer.from("uncompressed data"))])); }); });
it("should decompress with 'gzip'", () => { const mw = Middleware({ method: "gzip", threshold: 0 }); mw.created(broker); const meta = {}; const next = jest.fn(); const receive = mw.transporterReceive.call(broker, next); const compressedData = Buffer.concat([COMPRESSED_FLAG, zlib.gzipSync(Buffer.from("compressed data"))]); return receive("topic", compressedData, meta).catch(protectReject).then(() => { expect(next).toHaveBeenCalledTimes(1); expect(next).toHaveBeenCalledWith("topic", Buffer.from("compressed data"), meta); }); });
async writeTile(binaryBuffer, z, y, x) { const self = this; const compressedBuffer = zlib.gzipSync(binaryBuffer, {level: zlib.constants.Z_BEST_COMPRESSION}); await self.updateImage(z, x, y, compressedBuffer); }
function encodeSync(profile) { const buffer = profile_1.perftools.profiles.Profile.encode(profile).finish(); return zlib_1.gzipSync(buffer); }
getAppContentToBundle() { const mainAppFileCont = gzipSync(fs.readFileSync(this.appFile)).toString('base64'); return Buffer.from(this.appName).toString('base64') + '\n' + mainAppFileCont; }
const reducer = (acc, val, opt, wc) => { acc += JSON.stringify(val) + '\n'; if (acc.length >= 65536) { if (opt.gzip) { fs.appendFileSync(wc.exportFile, zlib.gzipSync(acc, { chunckSize: 65536, level: zlib.Z_BEST_SPEED })); } else { fs.appendFileSync(wc.exportFile, acc); } acc = ''; } return acc; }
const buffer = pbf.finish(); const binBuffer = Buffer.from(buffer); const compressedBuffer = zlib.gzipSync(binBuffer, {level: zlib.constants.Z_BEST_COMPRESSION});
function deflate_gzip(value) { return zlib.gzipSync(value); }
if(encodingType.indexOf('gzip') > -1){ response.setHeader('content-encoding','gzip'); response.write(zlib.gzipSync(data)); }else if(encodingType.indexOf('deflate') > -1){ response.setHeader('content-encoding','deflate');
it("returns gzipped body", function() { expect(this.res.end).toHaveBeenCalledWith( zlib.gzipSync("pre-rendered body") ); });
const jsonFileReducer = (acc, val, opt, wc) => { acc += JSON.stringify(val) + '\n'; if (acc.length >= 65536) { if (opt.gzip) { fs.appendFileSync(wc.exportFile, zlib.gzipSync(acc, { chunckSize: 65536, level: zlib.Z_BEST_SPEED })); } else { fs.appendFileSync(wc.exportFile, acc); } acc = ''; } return acc; }