updated streams ponyfill

This commit is contained in:
Danny Coates 2018-07-17 11:40:01 -07:00
parent f4f8332f96
commit f58b6194ce
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
4 changed files with 42 additions and 38 deletions

35
app/streams.js Normal file
View file

@ -0,0 +1,35 @@
/* global TransformStream ReadableStream */
import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter';
import {
TransformStream as TransformStreamPony,
ReadableStream as ReadableStreamPony
} from 'web-streams-ponyfill';
const toNativeReadable = createReadableStreamWrapper(ReadableStream);
const toPonyReadable = createReadableStreamWrapper(ReadableStreamPony);
export let TStream;
if (typeof TransformStream === 'function') {
TStream = TransformStream;
} else {
TStream = TransformStreamPony;
TStream.prototype.isPony = true;
}
export let RStream = ReadableStream;
try {
new ReadableStream().pipeThrough(new TransformStream());
} catch (e) {
RStream = ReadableStreamPony;
RStream.prototype.isPony = true;
RStream.prototype.toNative = function() {
return toNativeReadable(this);
};
}
export function wrapReadable(stream) {
if (RStream === ReadableStream) {
return stream;
}
return toPonyReadable(stream);
}