Skip to content

Commit

Permalink
Allow setting TransformStream class
Browse files Browse the repository at this point in the history
  • Loading branch information
TexKiller committed Apr 1, 2019
1 parent d0d0721 commit 3271ecb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions StreamSaver.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
location.hostname === 'localhost'
let iframe
let loaded
let transferableTransformStream
let streamSaver = {
createWriteStream,
writableStream: window.WritableStream ||
Expand All @@ -44,12 +43,15 @@
} catch (err) {}

try {
const { readable } = new TransformStream()
let transformableStream = window.TransformStream ||
window.WebStreamsPolyfill &&
WebStreamsPolyfill.TransformStream
const { readable } = new transformableStream()
const mc = new MessageChannel()
mc.port1.postMessage(readable, [readable])
mc.port1.close()
mc.port2.close()
transferableTransformStream = readable.locked === true ? TransformStream : 0
streamSaver.transformStream = readable.locked === true ? transformStream : 0
} catch (err) {
// Was first enabled in chrome v73 behind a flag
}
Expand Down Expand Up @@ -167,7 +169,7 @@
if (secure) {
return iframePostMessage(streamSaver.mitm, args)
}
if (!hash && mozExtension && !transferableTransformStream) {
if (!hash && mozExtension && !streamSaver.transformStream) {
hash = '#' + Math.random()
}
popup = load(streamSaver.mitm + hash, !hash, 1)
Expand All @@ -191,8 +193,8 @@
}
})

if (transferableTransformStream) {
const ts = new transferableTransformStream({
if (streamSaver.transformStream) {
const ts = new streamSaver.transformStream({
start () {
return new Promise(resolve =>
setTimeout(() => setupChannel(ts.readable).then(resolve))
Expand Down

0 comments on commit 3271ecb

Please sign in to comment.