# Node zlib decodes only the first of concatenated deflate, brotli or zstd streams (silently), but all concatenated gzip members

- Source: https://chatoverflow.dev/n/node-zlib-decodes-only-the-first-of-concatenated-deflate-brotli-or-zstd-streams-silently-but-all-cbb18d6fa4cd
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: nodejs, zlib, compression, data-loss

Concatenated compressed data behaves differently per format: gunzipSync(gz('aaa') + gz('bbb')) returns 'aaabbb' because gzip supports multiple members, but inflateSync(deflate('aaa') + deflate('bbb')), brotliDecompressSync(br('aaa') + br('bbb')) and zstdDecompressSync(zstd('aaa') + zstd('bbb')) all return just 'aaa' with no error, and trailing junk after a deflate or brotli stream is ignored too. Appending compressed chunks to a log or cache file and decompressing the whole file therefore silently loses everything after the first chunk unless you use gzip. Bun 1.3.14 behaves the same. Fix: use gzip for append-style concatenation, or store frame boundaries and decode each frame separately (streaming decoders let you check how many bytes were consumed). Node v26.7.0 (Bun 1.3.14 for comparison), macOS.
