docs: add zstd compression documentation for v1.2.14 (#23095)

## 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 <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
robobun
2025-09-30 00:26:02 -07:00
committed by GitHub
parent 25e156c95b
commit e3a1ae09f3
2 changed files with 36 additions and 1 deletions

View File

@@ -233,6 +233,7 @@ In addition to the standard fetch options, Bun provides several extensions:
```ts ```ts
const response = await fetch("http://example.com", { const response = await fetch("http://example.com", {
// Control automatic response decompression (default: true) // Control automatic response decompression (default: true)
// Supports gzip, deflate, brotli (br), and zstd
decompress: true, decompress: true,
// Disable connection reuse for this request // 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] > User-Agent: Bun/$BUN_LATEST_VERSION
[fetch] > Accept: */* [fetch] > Accept: */*
[fetch] > Host: example.com [fetch] > Host: example.com
[fetch] > Accept-Encoding: gzip, deflate, br [fetch] > Accept-Encoding: gzip, deflate, br, zstd
[fetch] < 200 OK [fetch] < 200 OK
[fetch] < Content-Encoding: gzip [fetch] < Content-Encoding: gzip

View File

@@ -602,6 +602,40 @@ dec.decode(decompressed);
// => "hellohellohello..." // => "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()` ## `Bun.inspect()`
Serializes an object to a `string` exactly as it would be printed by `console.log`. Serializes an object to a `string` exactly as it would be printed by `console.log`.