Added links to the Chrome & WebKit bugs that make me have to append .download to the filename & change the media type.
Expanded ready state 2 to DONE in two instances.
This commit is contained in:
+11
-6
@@ -1,6 +1,6 @@
|
||||
/* FileSaver.js
|
||||
* A saveAs() FileSaver implementation.
|
||||
* 2011-07-13
|
||||
* 2011-08-01
|
||||
*
|
||||
* By Eli Grey, http://eligrey.com
|
||||
* License: X11/MIT
|
||||
@@ -62,17 +62,18 @@ var saveAs = saveAs || (function(view) {
|
||||
var object_url = URL.createObjectURL(blob);
|
||||
target_view.location.href = object_url;
|
||||
deletion_queue.push(object_url);
|
||||
filesaver.readyState = 2; // DONE
|
||||
filesaver.readyState = filesaver.DONE;
|
||||
dispatch(filesaver, "writestart progress write writeend".split(" "));
|
||||
}
|
||||
, abortable = function(func) {
|
||||
return function() {
|
||||
if (filesaver.readyState !== 2) { // DONE
|
||||
if (filesaver.readyState !== filesaver.DONE) {
|
||||
return func.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
, target_view
|
||||
, slice
|
||||
;
|
||||
filesaver.readyState = filesaver.INIT;
|
||||
if (!name) {
|
||||
@@ -80,10 +81,14 @@ var saveAs = saveAs || (function(view) {
|
||||
}
|
||||
// Object and web filesystem URLs have a problem saving in WebKit when viewed
|
||||
// in a tab, so I force object URLs to save with application/octet-stream
|
||||
// and web filesystem URLs to save by appending .download to the filename.
|
||||
if (blob.webkitSlice && type !== force_saveable_type) {
|
||||
blob = blob.webkitSlice(0, blob.size, force_saveable_type);
|
||||
// http://code.google.com/p/chromium/issues/detail?id=91158
|
||||
if (view.chrome && type !== force_saveable_type) {
|
||||
slice = blob.slice || blob.webkitSlice;
|
||||
blob = slice.call(blob, 0, blob.size, force_saveable_type);
|
||||
}
|
||||
// Since I can't be sure that the guessed media type will trigger a download
|
||||
// in WebKit, I append .download to the filename.
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=65440
|
||||
if (webkit_req_fs && name !== "download") {
|
||||
name += ".download";
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
||||
var saveAs=saveAs||(function(l){"use strict";var k=l.URL||l.webkitURL||l,f=l.webkitRequestFileSystem,m=l.requestFileSystem||f||l.mozRequestFileSystem,c=function(n){(l.setImmediate||setTimeout)(function(){throw n},0)},j="application/octet-stream",h=0,g=[],e=function(){var o=g.length;while(o--){var n=g[o];if(typeof n==="string"){k.revokeObjectURL(n)}else{n.remove()}}g.length=0},i=function(o,n,r){n=[].concat(n);var q=n.length;while(q--){var s=o["on"+n[q]];if(typeof s==="function"){try{s.call(o,r||o)}catch(p){c(p)}}}},b=function(o,q){var n=this,r=o.type,t=function(){var u=k.createObjectURL(o);p.location.href=u;g.push(u);n.readyState=2;i(n,"writestart progress write writeend".split(" "))},s=function(u){return function(){if(n.readyState!==2){return u.apply(this,arguments)}}},p;n.readyState=n.INIT;if(!q){q="download"}if(o.webkitSlice&&r!==j){o=o.webkitSlice(0,o.size,j)}if(f&&q!=="download"){q+=".download"}if(r===j||f){p=self}else{p=open()}if(!m){t();return}h+=o.size;m(l.TEMPORARY,h,s(function(u){u.root.getDirectory("saved",{create:true,exclusive:false},s(function(v){var w=function(){v.getFile(q,{create:true,exclusive:false},s(function(x){x.createWriter(s(function(y){y.onwriteend=function(z){p.location.href=x.toURL();g.push(x);n.readyState=n.DONE;i(n,"writeend",z)};y.onerror=function(){var z=y.error;if(z.code!==z.ABORT_ERR){t()}};"writestart progress write abort".split(" ").forEach(function(z){y["on"+z]=n["on"+z]});y.write(o);n.abort=function(){y.abort();n.readyState=n.DONE};n.readyState=n.WRITING}),t)}),t)};v.getFile(q,{create:false},s(function(x){x.remove();w()}),s(function(x){if(x.code===x.NOT_FOUND_ERR){w()}else{t()}}))}),t)}),t)},a=b.prototype,d=function(n,o){return new b(n,o)};a.abort=function(){var n=this;n.readyState=n.DONE;i(n,"abort")};a.readyState=a.INIT=0;a.WRITING=1;a.DONE=2;a.error=a.onwritestart=a.onprogress=a.onwrite=a.onabort=a.onerror=a.onwriteend=null;l.addEventListener("unload",e,false);return d}(self));
|
||||
var saveAs=saveAs||(function(l){"use strict";var k=l.URL||l.webkitURL||l,f=l.webkitRequestFileSystem,m=l.requestFileSystem||f||l.mozRequestFileSystem,c=function(n){(l.setImmediate||setTimeout)(function(){throw n},0)},j="application/octet-stream",h=0,g=[],e=function(){var o=g.length;while(o--){var n=g[o];if(typeof n==="string"){k.revokeObjectURL(n)}else{n.remove()}}g.length=0},i=function(o,n,r){n=[].concat(n);var q=n.length;while(q--){var s=o["on"+n[q]];if(typeof s==="function"){try{s.call(o,r||o)}catch(p){c(p)}}}},b=function(o,q){var n=this,r=o.type,u=function(){var v=k.createObjectURL(o);p.location.href=v;g.push(v);n.readyState=n.DONE;i(n,"writestart progress write writeend".split(" "))},s=function(v){return function(){if(n.readyState!==n.DONE){return v.apply(this,arguments)}}},p,t;n.readyState=n.INIT;if(!q){q="download"}if(l.chrome&&r!==j){t=o.slice||o.webkitSlice;o=t.call(o,0,o.size,j)}if(f&&q!=="download"){q+=".download"}if(r===j||f){p=self}else{p=open()}if(!m){u();return}h+=o.size;m(l.TEMPORARY,h,s(function(v){v.root.getDirectory("saved",{create:true,exclusive:false},s(function(w){var x=function(){w.getFile(q,{create:true,exclusive:false},s(function(y){y.createWriter(s(function(z){z.onwriteend=function(A){p.location.href=y.toURL();g.push(y);n.readyState=n.DONE;i(n,"writeend",A)};z.onerror=function(){var A=z.error;if(A.code!==A.ABORT_ERR){u()}};"writestart progress write abort".split(" ").forEach(function(A){z["on"+A]=n["on"+A]});z.write(o);n.abort=function(){z.abort();n.readyState=n.DONE};n.readyState=n.WRITING}),u)}),u)};w.getFile(q,{create:false},s(function(y){y.remove();x()}),s(function(y){if(y.code===y.NOT_FOUND_ERR){x()}else{u()}}))}),u)}),u)},a=b.prototype,d=function(n,o){return new b(n,o)};a.abort=function(){var n=this;n.readyState=n.DONE;i(n,"abort")};a.readyState=a.INIT=0;a.WRITING=1;a.DONE=2;a.error=a.onwritestart=a.onprogress=a.onwrite=a.onabort=a.onerror=a.onwriteend=null;l.addEventListener("unload",e,false);return d}(self));
|
||||
Reference in New Issue
Block a user