How to use web-streams-polyfill - 9 common examples

To help you get started, we’ve selected a few web-streams-polyfill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nasa-gibs / worldview / web / ext / gifwriter / gifwriter.js View on Github external
buf[p++] = 0x50;
      buf[p++] = 0x45;
      buf[p++] = 0x32;
      buf[p++] = 0x2e;
      buf[p++] = 0x30;
      // Sub-block
      buf[p++] = 0x03;
      buf[p++] = 0x01;
      buf[p++] = loop_count & 0xff;
      buf[p++] = loop_count >> 8 & 0xff;
      buf[p++] = 0x00; // Terminator.
    }
    var self = this;
    var reader = rs.getReader();

    return new ReadableStream({
      start: function start(controller) {
        controller.enqueue(new Uint8Array(buf));
      },
      pull: function pull(controller) {
        return reader.read().then(function (_ref2) {
          var done = _ref2.done,
              value = _ref2.value;

          if (done) {
            controller.enqueue(new Uint8Array([0x3b]));
            controller.close();
            return;
          }

          self.addFrame.apply(self, [controller].concat(value));
        });
github nasa-gibs / worldview / web / js / map / animation / gif-stream.js View on Github external
getStream(frames, ctx) {
    var options = this.options;
    var width = options.gifWidth;
    var height = options.gifHeight;
    var totalImages = frames.length;
    var processedImages = 0;
    var self = this;
    var rs = new ReadableStream({
      pull: function pull(controller) {
        var frame = frames.shift();
        if (!frame) controller.close();
        var imgData, rgbComponents, paletteRGB, nq, paletteArray, numberPixels, pixels;
        var r, g, b;
        var k = 0;
        var delay = (frame.delay) ? frame.delay / 10 : 100;
        processedImages++;
        delay = (processedImages === totalImages && options.extraLastFrameDelay) ? delay + (options.extraLastFrameDelay / 10) : delay;// Add an extra
        ctx = self.addFrameDetails(ctx, frame);
        imgData = ctx.getImageData(0, 0, width, height);
        rgbComponents = dataToRGB(imgData.data, imgData.width, imgData.height);
        nq = new NeuQuant(rgbComponents, rgbComponents.length, 15);
        paletteRGB = nq.process();
        paletteArray = new Uint32Array(componentizedPaletteToArray(paletteRGB));
        numberPixels = imgData.height * imgData.width;
github superfly / fly / v8env / body.js View on Github external
function emptyStream() {
		return new ReadableStream({
			start(controller) {
				controller.close()
			}
		})
	}
}
github superfly / fly / v8env / body.js View on Github external
function streamFromString(str) {
		return new ReadableStream({
			start(controller) {
				controller.enqueue(str)
				controller.close()
			},
			cancel() { },
			pull() { }
		})
	}
github superfly / fly / v8env / body.js View on Github external
function _read(ref) {
		let closed = false
		return new ReadableStream({
			start(controller) {
				dispatcher.dispatch("readProxyStream",
					ref,
					new ivm.Reference((name, ...args) => {
						if (name === "close" || name === "end") {
							if (!closed) {
								closed = true
								controller.close()
							}
						} else if (name === "error") {
							controller.error(new Error(args[0]))
						} else if (name === "data") {
							controller.enqueue(args[0])
						} else
							logger.debug("unhandled event", name)
					})
github bjornharrtell / flatgeobuf / src / ts / streams / utils.ts View on Github external
if (destroyed) return
      nodeStream.resume()
    }
  
    function cancel () {
      destroyed = true
  
      for (var name in listeners) nodeStream.removeListener(name, listeners[name])
  
      nodeStream.push(null)
      nodeStream.pause()
      if (nodeStream.destroy) nodeStream.destroy()
      else if (nodeStream.close) nodeStream.close()
    }
  
    return new ReadableStream({start: start, pull: pull, cancel: cancel})
  }
github dollarshaveclub / cloudworker / lib / kv.js View on Github external
const value = this.store.get(key)
    if (value === undefined) {
      return Promise.resolve(null)
    }

    switch (type) {
      case 'text':
        return Promise.resolve(value.toString())
      case 'arrayBuffer':
        return Promise.resolve(Uint8Array.from(value).buffer)
      case 'json':
        return Promise.resolve(JSON.parse(value.toString()))
      case 'stream':

        const { readable, writable } = new streams.TransformStream()
        const writer = writable.getWriter()
        writer.write(Uint8Array.from(value)).then(() => writer.close())
        return Promise.resolve(readable)
    }
  }
github dollarshaveclub / cloudworker / lib / runtime / stream.js View on Github external
const streams = require('web-streams-polyfill')

module.exports.ReadableStream = streams.ReadableStream
module.exports.WritableStream = streams.WritableStream
module.exports.TransformStream = streams.TransformStream
github mozilla / pdfjs-dist / lib / shared / streams_polyfill.js View on Github external
if (typeof ReadableStream !== 'undefined') {
    try {
      new ReadableStream({
        start: function start(controller) {
          controller.close();
        }
      });
      isReadableStreamSupported = true;
    } catch (e) {}
  }

  if (isReadableStreamSupported) {
    exports.ReadableStream = ReadableStream;
  } else {
    exports.ReadableStream = require('web-streams-polyfill/dist/ponyfill').ReadableStream;
  }
}

web-streams-polyfill

Web Streams, based on the WHATWG spec reference implementation

MIT
Latest version published 8 months ago

Package Health Score

80 / 100
Full package analysis