From e3a1ae09f3328523fe4cc894a00cd8c6811734ff Mon Sep 17 00:00:00 2001 From: robobun Date: Tue, 30 Sep 2025 00:26:02 -0700 Subject: [PATCH] docs: add zstd compression documentation for v1.2.14 (#23095) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Documents zstd compression features introduced in Bun v1.2.14 - Adds missing API documentation for zstd utilities ## Changes - Updated `docs/api/fetch.md` to include zstd in Accept-Encoding examples and note automatic decompression support - Added `Bun.zstdCompress()/zstdCompressSync()` and `Bun.zstdDecompress()/zstdDecompressSync()` documentation to `docs/api/utils.md` - Documented compression levels (1-22) with concise usage examples ## Note HTTP/2 features (`maxSendHeaderBlockLength` and `setNextStreamID`) were not added per request to avoid updating nodejs-apis.md. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Bot Co-authored-by: Claude Co-authored-by: Jarred Sumner Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- docs/api/fetch.md | 3 ++- docs/api/utils.md | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/api/fetch.md b/docs/api/fetch.md index 268e737db5..f9ccd9c272 100644 --- a/docs/api/fetch.md +++ b/docs/api/fetch.md @@ -233,6 +233,7 @@ In addition to the standard fetch options, Bun provides several extensions: ```ts const response = await fetch("http://example.com", { // Control automatic response decompression (default: true) + // Supports gzip, deflate, brotli (br), and zstd decompress: true, // Disable connection reuse for this request @@ -339,7 +340,7 @@ This will print the request and response headers to your terminal: [fetch] > User-Agent: Bun/$BUN_LATEST_VERSION [fetch] > Accept: */* [fetch] > Host: example.com -[fetch] > Accept-Encoding: gzip, deflate, br +[fetch] > Accept-Encoding: gzip, deflate, br, zstd [fetch] < 200 OK [fetch] < Content-Encoding: gzip diff --git a/docs/api/utils.md b/docs/api/utils.md index 809f1c9e84..b9c4e40540 100644 --- a/docs/api/utils.md +++ b/docs/api/utils.md @@ -602,6 +602,40 @@ dec.decode(decompressed); // => "hellohellohello..." ``` +## `Bun.zstdCompress()` / `Bun.zstdCompressSync()` + +Compresses a `Uint8Array` using the Zstandard algorithm. + +```ts +const buf = Buffer.from("hello".repeat(100)); + +// Synchronous +const compressedSync = Bun.zstdCompressSync(buf); +// Asynchronous +const compressedAsync = await Bun.zstdCompress(buf); + +// With compression level (1-22, default: 3) +const compressedLevel = Bun.zstdCompressSync(buf, { level: 6 }); +``` + +## `Bun.zstdDecompress()` / `Bun.zstdDecompressSync()` + +Decompresses a `Uint8Array` using the Zstandard algorithm. + +```ts +const buf = Buffer.from("hello".repeat(100)); +const compressed = Bun.zstdCompressSync(buf); + +// Synchronous +const decompressedSync = Bun.zstdDecompressSync(compressed); +// Asynchronous +const decompressedAsync = await Bun.zstdDecompress(compressed); + +const dec = new TextDecoder(); +dec.decode(decompressedSync); +// => "hellohellohello..." +``` + ## `Bun.inspect()` Serializes an object to a `string` exactly as it would be printed by `console.log`.