whatwg / compression

Compression Standard
https://compression.spec.whatwg.org/
Other
85 stars 21 forks source link

Compress arraybuffer example #29

Closed jakearchibald closed 4 years ago

jakearchibald commented 4 years ago

https://github.com/wicg/compression/blob/master/explainer.md#deflate-compress-an-arraybuffer-to-a-uint8array

It could be:

function compressArrayBuffer(input) {
  const stream = new Blob(input)
    .stream()
    .pipeThrough(new CompressionStream('deflate'));
  return new Response(stream).arrayBuffer();
}

I guess it's a little hacky, but the following example already uses blob/response, so maybe it's ok?

jakearchibald commented 4 years ago

PR https://github.com/WICG/compression/pull/30