streams

This module is only available to use in your EdgeWorker code bundles when using the responseProvider event handler.

Exports implementations of ByteLengthQueuingStrategy, CountQueuingStrategy, ReadableStream, TransformStream, and WritableStream, as described in https://streams.spec.whatwg.org/.

import { createResponse } from 'create-response';
import { httpRequest } from 'http-request';
import { ReadableStream, WritableStream } from 'streams';
import { TextEncoderStream, TextDecoderStream } from 'text-encode-transform';
class UppercaseStream {
  constructor () {
    let readController = null;
    this.readable = new ReadableStream({
      start (controller) {
        readController = controller;
      }
    });
    this.writable = new WritableStream({
      write (text) {
        readController.enqueue(text.toUpperCase());
      },
      close (controller) {
        readController.close();
      }
    });
  }
}
export async function responseProvider (request) {
  const response = await httpRequest('http://example.com/javascripts/jquery-3.3.1.min.js');
  return createResponse(
    response.status,
    {},
    response.body
      .pipeThrough(new TextDecoderStream())
      .pipeThrough(new UppercaseStream())
      .pipeThrough(new TextEncoderStream())
  );
}