Semi-workaround for #205
This solution still isn't technically correct because it could take more than 40 seconds to download a file. I could simply not revoke any files, but then users would run into issues once they have saved a cumulative total of over 500MB ( https://bugs.chromium.org/p/chromium/issues/detail?id=375297 ) Complain to @sicking and @arunranga for creating and standardizing an incomplete revocation API.
This commit is contained in:
+19
-9
@@ -1,6 +1,6 @@
|
|||||||
/* FileSaver.js
|
/* FileSaver.js
|
||||||
* A saveAs() FileSaver implementation.
|
* A saveAs() FileSaver implementation.
|
||||||
* 1.1.20160319
|
* 1.1.20160328
|
||||||
*
|
*
|
||||||
* By Eli Grey, http://eligrey.com
|
* By Eli Grey, http://eligrey.com
|
||||||
* License: MIT
|
* License: MIT
|
||||||
@@ -40,10 +40,8 @@ var saveAs = saveAs || (function(view) {
|
|||||||
}
|
}
|
||||||
, force_saveable_type = "application/octet-stream"
|
, force_saveable_type = "application/octet-stream"
|
||||||
, fs_min_size = 0
|
, fs_min_size = 0
|
||||||
// See https://code.google.com/p/chromium/issues/detail?id=375297#c7 and
|
// the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
|
||||||
// https://github.com/eligrey/FileSaver.js/commit/485930a#commitcomment-8768047
|
, arbitrary_revoke_timeout = 1000 * 40 // in ms
|
||||||
// for the reasoning behind the timeout and revocation flow
|
|
||||||
, arbitrary_revoke_timeout = 500 // in ms
|
|
||||||
, revoke = function(file) {
|
, revoke = function(file) {
|
||||||
var revoker = function() {
|
var revoker = function() {
|
||||||
if (typeof file === "string") { // file is an object URL
|
if (typeof file === "string") { // file is an object URL
|
||||||
@@ -52,11 +50,23 @@ var saveAs = saveAs || (function(view) {
|
|||||||
file.remove();
|
file.remove();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (view.chrome) {
|
/* // Take note W3C:
|
||||||
revoker();
|
var
|
||||||
} else {
|
uri = typeof file === "string" ? file : file.toURL()
|
||||||
setTimeout(revoker, arbitrary_revoke_timeout);
|
, revoker = function(evt) {
|
||||||
|
// idealy DownloadFinishedEvent.data would be the URL requested
|
||||||
|
if (evt.data === uri) {
|
||||||
|
if (typeof file === "string") { // file is an object URL
|
||||||
|
get_URL().revokeObjectURL(file);
|
||||||
|
} else { // file is a File
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
;
|
||||||
|
view.addEventListener("downloadfinished", revoker);
|
||||||
|
*/
|
||||||
|
setTimeout(revoker, arbitrary_revoke_timeout);
|
||||||
}
|
}
|
||||||
, dispatch = function(filesaver, event_types, event) {
|
, dispatch = function(filesaver, event_types, event) {
|
||||||
event_types = [].concat(event_types);
|
event_types = [].concat(event_types);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user