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`.