updated streams ponyfill
This commit is contained in:
parent
f4f8332f96
commit
f58b6194ce
4 changed files with 42 additions and 38 deletions
35
app/streams.js
Normal file
35
app/streams.js
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue