- From: Adam Rice <notifications@github.com>
- Date: Mon, 14 Oct 2019 22:53:27 -0700
- To: whatwg/streams <streams@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Tuesday, 15 October 2019 05:53:29 UTC
The main motivating example is this from the [CompressionStream explainer](https://github.com/ricea/compressstream-explainer/blob/master/README.md#example-code):
```javascript
async function compressArrayBuffer(in) {
const cs = new CompressionStream('deflate');
const writer = cs.writable.getWriter();
writer.write(in);
writer.close();
const out = [];
const reader = cs.readable.getReader();
let totalSize = 0;
while (true) {
const { value, done } = await reader.read();
if (done)
break;
out.push(value);
totalSize += value.byteLength;
}
const concatenated = new Uint8Array(totalSize);
let offset = 0;
for (const array of out) {
concatenated.set(array, offset);
offset += array.byteLength;
}
return concatenated;
}
```
where it took 3 lines just to create a stream containing a single ArrayBuffer chunk, something that feels like it should be a one-liner. This is also a possible solution to https://github.com/whatwg/fetch/issues/809.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1018#issuecomment-542049111
Received on Tuesday, 15 October 2019 05:53:29 UTC