From 7da886baaafd53d07684c49ea733317c7f1b4510 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 15 Aug 2025 12:17:04 -0400 Subject: [PATCH] Document ZSTD_WINDOW_BUFFER_SIZE --- src/unbundle/unbundle.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/unbundle/unbundle.zig b/src/unbundle/unbundle.zig index b3faa03005..a237fcd440 100644 --- a/src/unbundle/unbundle.zig +++ b/src/unbundle/unbundle.zig @@ -12,6 +12,13 @@ const base58 = @import("base58"); const TAR_EXTENSION = ".tar.zst"; const STREAM_BUFFER_SIZE: usize = 64 * 1024; // 64KB buffer for streaming operations +/// Size of the decompression window buffer for zstd. +/// 8MB (2^23 bytes) is the default and recommended size for zstd decompression. +/// This matches zstd's default maximum window size, allowing us to decompress +/// any standard zstd stream. Smaller buffers would fail on streams compressed +/// with larger window sizes. +const ZSTD_WINDOW_BUFFER_SIZE: usize = 1 << 23; // 8MB + /// Errors that can occur during the unbundle operation. pub const UnbundleError = error{ DecompressionFailed, @@ -290,7 +297,10 @@ pub fn unbundleStream( }; // Create zstandard decompressor - var zstd_stream = std.compress.zstd.decompressor(hashing_reader.reader(), .{}); + var window_buffer: [ZSTD_WINDOW_BUFFER_SIZE]u8 = undefined; + var zstd_stream = std.compress.zstd.decompressor(hashing_reader.reader(), .{ + .window_buffer = &window_buffer, + }); const decompressed_reader = zstd_stream.reader(); // Create tar reader