From 3656182d2aed884ccf79a599f0a895acd22f8862 Mon Sep 17 00:00:00 2001 From: cxvqo Date: Wed, 12 Feb 2025 21:03:08 +0200 Subject: [PATCH] fix: don't inflate/decompress if compressionThreshold is negative If compression is enabled, all following packets are encoded in the compressed packet format. Negative values will disable compression, meaning the packet format should remain in the uncompressed packet format. However, this packet is entirely optional, and if not sent, compression will also not be enabled (the notchian server does not send the packet when compression is disabled). --- src/transforms/compression.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/transforms/compression.js b/src/transforms/compression.js index 45b063522..1830b083a 100644 --- a/src/transforms/compression.js +++ b/src/transforms/compression.js @@ -51,6 +51,12 @@ class Decompressor extends Transform { if (value === 0) { this.push(chunk.slice(size)) return cb() + } else if (this.compressionThreshold < 0) { + const buf = Buffer.alloc(sizeOfVarInt(0) + chunk.length) + const offset = writeVarInt(0, buf, 0) + chunk.copy(buf, offset) + this.push(chunk) + return cb() } else { zlib.unzip(chunk.slice(size), { finishFlush: 2 /* Z_SYNC_FLUSH = 2, but when using Browserify/Webpack it doesn't exist */ }, (err, newBuf) => { /** Fix by lefela4. */ if (err) {