An API for decompressing a stream of data.

See

DecompressionStream on MDN

Example

In this example a request is made to httpbin.org/gzip and the response body is decompressed using gzip decompression.

View this example on Fiddle.

async function app(event) {
const backendResponse = await fetch("https://httpbin.org/gzip", { backend: "origin_0" });
let resp = new Response(backendResponse.body.pipeThrough(new DecompressionStream("gzip")), backendResponse);
resp.headers.delete('content-encoding');
return resp;
}
addEventListener("fetch", event => event.respondWith(app(event)));

Hierarchy

  • DecompressionStream

Constructors

Properties

Constructors

  • Creates a new DecompressionStream object which decompresses a stream of data.

    Throws

    Throws a TypeError if the format passed to the constructor is not supported.

    Example

    const gzip = new DecompressionStream("gzip");
    

    Parameters

    • format: "deflate" | "deflate-raw" | "gzip"

      The compression format to use.

    Returns DecompressionStream

Properties

Example

let stream = new DecompressionStream("gzip");
console.log(stream.readable instanceof ReadableStream); // true

Example

let stream = new DecompressionStream("gzip");
console.log(stream.writable instanceof WritableStream); // true

Generated using TypeDoc