streamsaver
Advanced tools
Comparing version 2.0.2 to 2.0.3
{ | ||
"name": "streamsaver", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "StreamSaver writes stream to the filesystem directly - asynchronous", | ||
@@ -5,0 +5,0 @@ "main": "StreamSaver.js", |
@@ -16,3 +16,2 @@ /* global chrome location ReadableStream define MessageChannel TransformStream */ | ||
const ponyfill = window.WebStreamsPolyfill || {} | ||
const once = { once: true } | ||
const isSecureContext = window.isSecureContext | ||
@@ -49,3 +48,3 @@ let useBlobFallback = /constructor/i.test(window.HTMLElement) || !!window.safari | ||
iframe.loaded = true | ||
}, once) | ||
}, { once: true }) | ||
document.body.appendChild(iframe) | ||
@@ -90,18 +89,8 @@ return iframe | ||
/** | ||
* Destroys a channel and return null | ||
* | ||
* @param {MessageChannel} channel [description] | ||
* @return {null} [description] | ||
*/ | ||
function destroyChannel (channel) { | ||
channel.port1.onmessage = null | ||
channel.port1.close() | ||
channel.port2.close() | ||
return null | ||
} | ||
try { | ||
// We can't look for service worker since it may still work on http | ||
!!new Response(new ReadableStream()) | ||
new Response(new ReadableStream()) | ||
if (isSecureContext && !('serviceWorker' in navigator)) { | ||
useBlobFallback = true | ||
} | ||
} catch (err) { | ||
@@ -183,3 +172,3 @@ useBlobFallback = true | ||
if (!opts.size) { | ||
if (opts.size) { | ||
response.headers['Content-Length'] = opts.size | ||
@@ -239,3 +228,3 @@ } | ||
// We never remove this iframes b/c it can interrupt saveAs | ||
// We never remove this iframes b/c it can interrupt saving | ||
makeIframe(evt.data.download) | ||
@@ -251,3 +240,3 @@ } | ||
mitmTransporter.postMessage(...args) | ||
}, once) | ||
}, { once: true }) | ||
} | ||
@@ -259,9 +248,2 @@ } | ||
return (!useBlobFallback && ts && ts.writable) || new streamSaver.WritableStream({ | ||
start () { | ||
// is called immediately, and should perform any actions | ||
// necessary to acquire access to the underlying sink. | ||
// If this process is asynchronous, it can return a promise | ||
// to signal success or failure. | ||
// return setupChannel() | ||
}, | ||
write (chunk) { | ||
@@ -303,6 +285,5 @@ if (useBlobFallback) { | ||
link.click() | ||
return | ||
} else { | ||
channel.port1.postMessage('end') | ||
} | ||
channel.port1.postMessage('end') | ||
channel = destroyChannel(channel) | ||
}, | ||
@@ -312,3 +293,6 @@ abort () { | ||
channel.port1.postMessage('abort') | ||
channel = destroyChannel(channel) | ||
channel.port1.onmessage = null | ||
channel.port1.close() | ||
channel.port2.close() | ||
channel = null | ||
} | ||
@@ -315,0 +299,0 @@ }, opts.writableStrategy) |
@@ -122,3 +122,3 @@ /* global self ReadableStream Response */ | ||
fileName = encodeURIComponent(fileName).replace(/['()]/g, escape).replace(/\*/g, '%2A') | ||
responseHeaders.set('Content-Disposition', "attachment; filename*=UTF-8''" + filename) | ||
responseHeaders.set('Content-Disposition', "attachment; filename*=UTF-8''" + fileName) | ||
} | ||
@@ -125,0 +125,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
65792
18
546