fetch-progress-indicators icon indicating copy to clipboard operation
fetch-progress-indicators copied to clipboard

Use TransformStream in Examples

Open anthumchris opened this issue 6 years ago • 0 comments

Refactor with TransformStream as described by @ricea:

The examples would be cleaner with TransformStream, but unfortunately no browser is shipping it yet. You could be really concise, something like (totally untested)

fetchEvent.respondWith(new Response(response.body.pipeThrough(new TransformStream({
  transform(chunk, controller) {
    loaded += chunk.length;
    progress({loaded, total});
    controller.enqueue(chunk);
  }
})), response));

anthumchris avatar Mar 05 '18 13:03 anthumchris