it("should decompress with 'deflate'", () => { const mw = Middleware({ 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.deflateSync(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); }); });
it("should compress with 'deflate'", () => { const mw = Middleware({ 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.deflateSync(Buffer.from("uncompressed data"))])); }); });
expect(next).toHaveBeenCalledTimes(1); expect(next).toHaveBeenCalledWith("topic", expect.any(Buffer), meta); expect(next.mock.calls[0][1]).toEqual(Buffer.concat([COMPRESSED_FLAG, zlib.deflateSync(longData)])); }); }); next.mockClear(); const receive = mw.transporterReceive.call(broker, next); const compressedData = Buffer.concat([COMPRESSED_FLAG, zlib.deflateSync(shortData)]);
static encode(message) { message.type = Message.Type[message.type]; if (message.json) { message.json = JSON.stringify(message.json); } const buffer = Message.encode(Message.create(message)).finish(); if (buffer.length > 1024) { return zlib.deflateSync(buffer); } return buffer; }
_encodePayload(){ let buf = Zlib.deflateSync(this.payload.getBuffer(), {level: this._compressionLevel}); this.append(buf); }
const encryptedOrderSignature = (ebicsAccount, document, transactionKey, key, xmlOptions) => { const dst = zlib.deflateSync(orderSignature(ebicsAccount, document, key, xmlOptions)); const cipher = crypto.createCipheriv('aes-128-cbc', transactionKey, Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])).setAutoPadding(false); return Buffer.concat([cipher.update(Crypto.pad(dst)), cipher.final()]).toString('base64'); }
persist() { const { x, z, needsPropagation, voxels, world: { storage }, } = this; if (!storage) { return; } fs.writeFileSync(path.join(storage, `${x}_${z}.json`), JSON.stringify({ needsPropagation, voxels: zlib.deflateSync(voxels).toString('base64'), })); this.needsPersistence = false; }
// http://www.museek-plus.org/wiki/SoulseekProtocol#PeerCode5 function encodeShares(packet, shareList, compress = true) { let dirs = Object.keys(shareList); let compressed = new Message(); compressed.int32(dirs.length); for (let dir of dirs) { compressed.str(dir.replace(/\//g, '\\')); encodeFiles(compressed, shareList[dir]); } if (compress) { compressed = zlib.deflateSync(compressed.data); } packet.writeBuffer(compressed); }
}else if(encodingType.indexOf('deflate') > -1){ response.setHeader('content-encoding','deflate'); response.write(zlib.deflateSync(data));
const encryptedOrderData = (document, transactionKey) => { const dst = zlib.deflateSync(document.replace(/\n|\r/g, '')); const cipher = crypto.createCipheriv('aes-128-cbc', transactionKey, Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])).setAutoPadding(false); return Buffer.concat([cipher.update(Crypto.pad(dst)), cipher.final()]).toString('base64'); }