Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be09a02e8c | ||
|
|
72effade4d | ||
|
|
3ecf5a9f55 | ||
|
|
6d09d0980b | ||
|
|
00183093bf | ||
|
|
cf70d125b0 | ||
|
|
bbecae4d41 | ||
|
|
b08a6d256c | ||
|
|
767f830766 | ||
|
|
74846b33fe | ||
|
|
556af82e6a | ||
|
|
15d96ca835 | ||
|
|
047fa34d15 | ||
|
|
5183da9c57 | ||
|
|
b796e069a9 | ||
|
|
410208d4f9 | ||
|
|
70c261d026 | ||
|
|
f3b45ae580 | ||
|
|
31eccd14f9 | ||
|
|
eb11f655e6 | ||
|
|
eaeac8dc3c | ||
|
|
9e931126f5 | ||
|
|
37d757bbc6 | ||
|
|
4de5ebccc8 | ||
|
|
5cbe331ec8 | ||
|
|
a67731daf4 | ||
|
|
660c35cdb8 | ||
|
|
5db588a568 | ||
|
|
1144ac42bb | ||
|
|
00e540fda5 | ||
|
|
23d400231f | ||
|
|
e865e37af9 | ||
|
|
a606064f37 | ||
|
|
28a86d90c4 | ||
|
|
5914e2a573 | ||
|
|
6356c3f6f6 | ||
|
|
24f9aaca80 | ||
|
|
f1959c87cd | ||
|
|
dfd58561fb | ||
|
|
a5dbf55c17 | ||
|
|
5978f3c577 | ||
|
|
9570cf7362 | ||
|
|
b1158d0c33 | ||
|
|
b6c236d96d | ||
|
|
164deec5ab | ||
|
|
99a89750b0 | ||
|
|
ff675f8052 | ||
|
|
17d5c67eb3 | ||
|
|
70bb521e5d | ||
|
|
b4c11367c0 | ||
|
|
281a1c1a93 | ||
|
|
d02373e40d | ||
|
|
d7f5db3244 | ||
|
|
b4a918669a | ||
|
|
5733e40e5a | ||
|
|
74f089808e | ||
|
|
fe42ec4055 | ||
|
|
0b90542535 | ||
|
|
c3e4a45021 | ||
|
|
db089ce81e | ||
|
|
1bf9b35b54 | ||
|
|
c347c51f6e | ||
|
|
945f08bc74 | ||
|
|
dffa3a4989 | ||
|
|
4db4a78aad | ||
|
|
d89ed13171 | ||
|
|
aa9f4e0e03 | ||
|
|
cafa1bfebb | ||
|
|
5ed507ef8a | ||
|
|
eb8d76f845 | ||
|
|
8739c467c6 | ||
|
|
d8870ded68 | ||
|
|
9751591281 | ||
|
|
b3cad8efea | ||
|
|
3843680045 | ||
|
|
4ac2c6d6c2 | ||
|
|
f1a8bf9fb0 | ||
|
|
b2bf6d86f5 | ||
|
|
0b137cf80a | ||
|
|
d84a5c2f3a | ||
|
|
47ff4cd74a | ||
|
|
c0c85f387b | ||
|
|
3eeddf1145 | ||
|
|
bc0ba24aaa | ||
|
|
ae387dbbac | ||
|
|
b610731175 | ||
|
|
9aee871752 | ||
|
|
1bb6b90443 | ||
|
|
a5a0ae83db | ||
|
|
7b242c2d78 |
@@ -0,0 +1,3 @@
|
|||||||
|
node_modules/
|
||||||
|
.DS_Store
|
||||||
|
.idea/
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
# Changelog
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2.0.0] - 2018-10-17
|
||||||
|
|
||||||
|
- Removed eval to resolve CSP [#465]
|
||||||
|
|
||||||
|
## [2.0.0-rc.4] - 2018-10-17
|
||||||
|
|
||||||
|
- Don’t throw on module.exports
|
||||||
|
|
||||||
|
## [2.0.0-rc.3] - 2018-09-27
|
||||||
|
|
||||||
|
- Switch export method
|
||||||
|
|
||||||
|
## [2.0.0-rc.2] - 2018-09-26
|
||||||
|
|
||||||
|
- Added a changelog.md
|
||||||
|
- Reverted `a.click()` to use dispatch with a try-catch ([#465], [#382])
|
||||||
|
- Made third argument to an object where you have to pass `{ autoBom: true }`
|
||||||
|
- boolean are depricated but still works
|
||||||
|
|
||||||
|
## [2.0.0-rc.1] - 2018-09-26
|
||||||
|
|
||||||
|
- saveAs don't return anything
|
||||||
|
- The object that dispatched `writestart progress write writeend` are gone
|
||||||
|
- detecting such features was never possible and nobody seems to use it.
|
||||||
|
- Removed the demo folder
|
||||||
|
- Removed date/version from top of the file
|
||||||
|
- Dosen't crash in web workers ([#449])
|
||||||
|
- Support saving urls ([#260] with workarounds for cross origin)
|
||||||
|
- Uses babel universal module pattern (UMD) to export the package
|
||||||
|
- Provides source map now as well.
|
||||||
|
- use a[download] before msSaveAs ([#193], [#294])
|
||||||
|
- removed dist from .gitignore (npm uses it if it don't find a .npmignore)
|
||||||
|
- autoBom is now reversed so you have to tell when you want to use autoBom ([#432])
|
||||||
|
- `a.click()` since there are new and depricated event constructors that works differently ([#382])
|
||||||
|
- opens up a new popup (tab) directly for the fallback method since the FileReader is async
|
||||||
|
- removed the explicitly MSIE [1-9] check
|
||||||
|
- Uses new anchor link for each save (might solve multiple download problems)
|
||||||
|
|
||||||
|
[#382]: https://github.com/eligrey/FileSaver.js/issues/382
|
||||||
|
[#449]: https://github.com/eligrey/FileSaver.js/issues/449
|
||||||
|
[#260]: https://github.com/eligrey/FileSaver.js/issues/260
|
||||||
|
[#193]: https://github.com/eligrey/FileSaver.js/issues/193
|
||||||
|
[#294]: https://github.com/eligrey/FileSaver.js/issues/294
|
||||||
|
[#432]: https://github.com/eligrey/FileSaver.js/issues/432
|
||||||
|
[#382]: https://github.com/eligrey/FileSaver.js/issues/382
|
||||||
|
[#465]: https://github.com/eligrey/FileSaver.js/issues/465
|
||||||
|
[#469]: https://github.com/eligrey/FileSaver.js/issues/469
|
||||||
|
[#470]: https://github.com/eligrey/FileSaver.js/issues/470
|
||||||
|
[#491]: https://github.com/eligrey/FileSaver.js/issues/491
|
||||||
-281
@@ -1,281 +0,0 @@
|
|||||||
/* FileSaver.js
|
|
||||||
* A saveAs() FileSaver implementation.
|
|
||||||
* 1.2.2
|
|
||||||
*
|
|
||||||
* By Eli Grey, http://eligrey.com
|
|
||||||
* License: MIT
|
|
||||||
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*global self */
|
|
||||||
/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
|
|
||||||
|
|
||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
|
||||||
|
|
||||||
var saveAs = saveAs || (function(view) {
|
|
||||||
"use strict";
|
|
||||||
// IE <10 is explicitly unsupported
|
|
||||||
if (typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var
|
|
||||||
doc = view.document
|
|
||||||
// only get URL when necessary in case Blob.js hasn't overridden it yet
|
|
||||||
, get_URL = function() {
|
|
||||||
return view.URL || view.webkitURL || view;
|
|
||||||
}
|
|
||||||
, save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
|
|
||||||
, can_use_save_link = "download" in save_link
|
|
||||||
, click = function(node) {
|
|
||||||
var event = new MouseEvent("click");
|
|
||||||
node.dispatchEvent(event);
|
|
||||||
}
|
|
||||||
, is_safari = /Version\/[\d\.]+.*Safari/.test(navigator.userAgent)
|
|
||||||
, webkit_req_fs = view.webkitRequestFileSystem
|
|
||||||
, req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
|
|
||||||
, throw_outside = function(ex) {
|
|
||||||
(view.setImmediate || view.setTimeout)(function() {
|
|
||||||
throw ex;
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
, force_saveable_type = "application/octet-stream"
|
|
||||||
, fs_min_size = 0
|
|
||||||
// the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to
|
|
||||||
, arbitrary_revoke_timeout = 1000 * 40 // in ms
|
|
||||||
, revoke = function(file) {
|
|
||||||
var revoker = function() {
|
|
||||||
if (typeof file === "string") { // file is an object URL
|
|
||||||
get_URL().revokeObjectURL(file);
|
|
||||||
} else { // file is a File
|
|
||||||
file.remove();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
/* // Take note W3C:
|
|
||||||
var
|
|
||||||
uri = typeof file === "string" ? file : file.toURL()
|
|
||||||
, 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) {
|
|
||||||
event_types = [].concat(event_types);
|
|
||||||
var i = event_types.length;
|
|
||||||
while (i--) {
|
|
||||||
var listener = filesaver["on" + event_types[i]];
|
|
||||||
if (typeof listener === "function") {
|
|
||||||
try {
|
|
||||||
listener.call(filesaver, event || filesaver);
|
|
||||||
} catch (ex) {
|
|
||||||
throw_outside(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
, auto_bom = function(blob) {
|
|
||||||
// prepend BOM for UTF-8 XML and text/* types (including HTML)
|
|
||||||
// note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF
|
|
||||||
if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
|
|
||||||
return new Blob([String.fromCharCode(0xFEFF), blob], {type: blob.type});
|
|
||||||
}
|
|
||||||
return blob;
|
|
||||||
}
|
|
||||||
, FileSaver = function(blob, name, no_auto_bom) {
|
|
||||||
if (!no_auto_bom) {
|
|
||||||
blob = auto_bom(blob);
|
|
||||||
}
|
|
||||||
// First try a.download, then web filesystem, then object URLs
|
|
||||||
var
|
|
||||||
filesaver = this
|
|
||||||
, type = blob.type
|
|
||||||
, blob_changed = false
|
|
||||||
, object_url
|
|
||||||
, target_view
|
|
||||||
, dispatch_all = function() {
|
|
||||||
dispatch(filesaver, "writestart progress write writeend".split(" "));
|
|
||||||
}
|
|
||||||
// on any filesys errors revert to saving with object URLs
|
|
||||||
, fs_error = function() {
|
|
||||||
if (target_view && is_safari && typeof FileReader !== "undefined") {
|
|
||||||
// Safari doesn't allow downloading of blob urls
|
|
||||||
var reader = new FileReader();
|
|
||||||
reader.onloadend = function() {
|
|
||||||
var base64Data = reader.result;
|
|
||||||
target_view.location.href = "data:attachment/file" + base64Data.slice(base64Data.search(/[,;]/));
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
dispatch_all();
|
|
||||||
};
|
|
||||||
reader.readAsDataURL(blob);
|
|
||||||
filesaver.readyState = filesaver.INIT;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// don't create more object URLs than needed
|
|
||||||
if (blob_changed || !object_url) {
|
|
||||||
object_url = get_URL().createObjectURL(blob);
|
|
||||||
}
|
|
||||||
if (target_view) {
|
|
||||||
target_view.location.href = object_url;
|
|
||||||
} else {
|
|
||||||
var new_tab = view.open(object_url, "_blank");
|
|
||||||
if (new_tab === undefined && is_safari) {
|
|
||||||
// Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html
|
|
||||||
view.location.href = object_url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
dispatch_all();
|
|
||||||
revoke(object_url);
|
|
||||||
}
|
|
||||||
, abortable = function(func) {
|
|
||||||
return function() {
|
|
||||||
if (filesaver.readyState !== filesaver.DONE) {
|
|
||||||
return func.apply(this, arguments);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
, create_if_not_found = {create: true, exclusive: false}
|
|
||||||
, slice
|
|
||||||
;
|
|
||||||
filesaver.readyState = filesaver.INIT;
|
|
||||||
if (!name) {
|
|
||||||
name = "download";
|
|
||||||
}
|
|
||||||
if (can_use_save_link) {
|
|
||||||
object_url = get_URL().createObjectURL(blob);
|
|
||||||
setTimeout(function() {
|
|
||||||
save_link.href = object_url;
|
|
||||||
save_link.download = name;
|
|
||||||
click(save_link);
|
|
||||||
dispatch_all();
|
|
||||||
revoke(object_url);
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Object and web filesystem URLs have a problem saving in Google Chrome when
|
|
||||||
// viewed in a tab, so I force save with application/octet-stream
|
|
||||||
// http://code.google.com/p/chromium/issues/detail?id=91158
|
|
||||||
// Update: Google errantly closed 91158, I submitted it again:
|
|
||||||
// https://code.google.com/p/chromium/issues/detail?id=389642
|
|
||||||
if (view.chrome && type && type !== force_saveable_type) {
|
|
||||||
slice = blob.slice || blob.webkitSlice;
|
|
||||||
blob = slice.call(blob, 0, blob.size, force_saveable_type);
|
|
||||||
blob_changed = true;
|
|
||||||
}
|
|
||||||
// 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";
|
|
||||||
}
|
|
||||||
if (type === force_saveable_type || webkit_req_fs) {
|
|
||||||
target_view = view;
|
|
||||||
}
|
|
||||||
if (!req_fs) {
|
|
||||||
fs_error();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fs_min_size += blob.size;
|
|
||||||
req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
|
|
||||||
fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
|
|
||||||
var save = function() {
|
|
||||||
dir.getFile(name, create_if_not_found, abortable(function(file) {
|
|
||||||
file.createWriter(abortable(function(writer) {
|
|
||||||
writer.onwriteend = function(event) {
|
|
||||||
target_view.location.href = file.toURL();
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
dispatch(filesaver, "writeend", event);
|
|
||||||
revoke(file);
|
|
||||||
};
|
|
||||||
writer.onerror = function() {
|
|
||||||
var error = writer.error;
|
|
||||||
if (error.code !== error.ABORT_ERR) {
|
|
||||||
fs_error();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
"writestart progress write abort".split(" ").forEach(function(event) {
|
|
||||||
writer["on" + event] = filesaver["on" + event];
|
|
||||||
});
|
|
||||||
writer.write(blob);
|
|
||||||
filesaver.abort = function() {
|
|
||||||
writer.abort();
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
};
|
|
||||||
filesaver.readyState = filesaver.WRITING;
|
|
||||||
}), fs_error);
|
|
||||||
}), fs_error);
|
|
||||||
};
|
|
||||||
dir.getFile(name, {create: false}, abortable(function(file) {
|
|
||||||
// delete file if it already exists
|
|
||||||
file.remove();
|
|
||||||
save();
|
|
||||||
}), abortable(function(ex) {
|
|
||||||
if (ex.code === ex.NOT_FOUND_ERR) {
|
|
||||||
save();
|
|
||||||
} else {
|
|
||||||
fs_error();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}), fs_error);
|
|
||||||
}), fs_error);
|
|
||||||
}
|
|
||||||
, FS_proto = FileSaver.prototype
|
|
||||||
, saveAs = function(blob, name, no_auto_bom) {
|
|
||||||
return new FileSaver(blob, name, no_auto_bom);
|
|
||||||
}
|
|
||||||
;
|
|
||||||
// IE 10+ (native saveAs)
|
|
||||||
if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
|
|
||||||
return function(blob, name, no_auto_bom) {
|
|
||||||
if (!no_auto_bom) {
|
|
||||||
blob = auto_bom(blob);
|
|
||||||
}
|
|
||||||
return navigator.msSaveOrOpenBlob(blob, name || "download");
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
FS_proto.abort = function() {
|
|
||||||
var filesaver = this;
|
|
||||||
filesaver.readyState = filesaver.DONE;
|
|
||||||
dispatch(filesaver, "abort");
|
|
||||||
};
|
|
||||||
FS_proto.readyState = FS_proto.INIT = 0;
|
|
||||||
FS_proto.WRITING = 1;
|
|
||||||
FS_proto.DONE = 2;
|
|
||||||
|
|
||||||
FS_proto.error =
|
|
||||||
FS_proto.onwritestart =
|
|
||||||
FS_proto.onprogress =
|
|
||||||
FS_proto.onwrite =
|
|
||||||
FS_proto.onabort =
|
|
||||||
FS_proto.onerror =
|
|
||||||
FS_proto.onwriteend =
|
|
||||||
null;
|
|
||||||
|
|
||||||
return saveAs;
|
|
||||||
}(
|
|
||||||
typeof self !== "undefined" && self
|
|
||||||
|| typeof window !== "undefined" && window
|
|
||||||
|| this.content
|
|
||||||
));
|
|
||||||
// `self` is undefined in Firefox for Android content script context
|
|
||||||
// while `this` is nsIContentFrameMessageManager
|
|
||||||
// with an attribute `content` that corresponds to the window
|
|
||||||
|
|
||||||
if (typeof module !== "undefined" && module.exports) {
|
|
||||||
module.exports.saveAs = saveAs;
|
|
||||||
} else if ((typeof define !== "undefined" && define !== null) && (define.amd !== null)) {
|
|
||||||
define([], function() {
|
|
||||||
return saveAs;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Vendored
-2
@@ -1,2 +0,0 @@
|
|||||||
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
|
||||||
var saveAs=saveAs||function(r){"use strict";if("undefined"==typeof navigator||!/MSIE [1-9]\./.test(navigator.userAgent)){var e=r.document,o=function(){return r.URL||r.webkitURL||r},t=e.createElementNS("http://www.w3.org/1999/xhtml","a"),f="download"in t,n=function(r){var e=new MouseEvent("click");r.dispatchEvent(e)},i=/Version\/[\d\.]+.*Safari/.test(navigator.userAgent),a=r.webkitRequestFileSystem,d=r.requestFileSystem||a||r.mozRequestFileSystem,C=function(e){(r.setImmediate||r.setTimeout)(function(){throw e},0)},m="application/octet-stream",S=0,h=4e4,g=function(r){var e=function(){"string"==typeof r?o().revokeObjectURL(r):r.remove()};setTimeout(e,h)},c=function(r,e,o){e=[].concat(e);for(var t=e.length;t--;){var f=r["on"+e[t]];if("function"==typeof f)try{f.call(r,o||r)}catch(n){C(n)}}},u=function(r){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(r.type)?new Blob([String.fromCharCode(65279),r],{type:r.type}):r},s=function(e,C,h){h||(e=u(e));var s,l,v,p=this,w=e.type,y=!1,x=function(){c(p,"writestart progress write writeend".split(" "))},R=function(){if(l&&i&&"undefined"!=typeof FileReader){var t=new FileReader;return t.onloadend=function(){var r=t.result;l.location.href="data:attachment/file"+r.slice(r.search(/[,;]/)),p.readyState=p.DONE,x()},t.readAsDataURL(e),void(p.readyState=p.INIT)}if((y||!s)&&(s=o().createObjectURL(e)),l)l.location.href=s;else{var f=r.open(s,"_blank");void 0===f&&i&&(r.location.href=s)}p.readyState=p.DONE,x(),g(s)},O=function(r){return function(){return p.readyState!==p.DONE?r.apply(this,arguments):void 0}},b={create:!0,exclusive:!1};return p.readyState=p.INIT,C||(C="download"),f?(s=o().createObjectURL(e),void setTimeout(function(){t.href=s,t.download=C,n(t),x(),g(s),p.readyState=p.DONE})):(r.chrome&&w&&w!==m&&(v=e.slice||e.webkitSlice,e=v.call(e,0,e.size,m),y=!0),a&&"download"!==C&&(C+=".download"),(w===m||a)&&(l=r),d?(S+=e.size,void d(r.TEMPORARY,S,O(function(r){r.root.getDirectory("saved",b,O(function(r){var o=function(){r.getFile(C,b,O(function(r){r.createWriter(O(function(o){o.onwriteend=function(e){l.location.href=r.toURL(),p.readyState=p.DONE,c(p,"writeend",e),g(r)},o.onerror=function(){var r=o.error;r.code!==r.ABORT_ERR&&R()},"writestart progress write abort".split(" ").forEach(function(r){o["on"+r]=p["on"+r]}),o.write(e),p.abort=function(){o.abort(),p.readyState=p.DONE},p.readyState=p.WRITING}),R)}),R)};r.getFile(C,{create:!1},O(function(r){r.remove(),o()}),O(function(r){r.code===r.NOT_FOUND_ERR?o():R()}))}),R)}),R)):void R())},l=s.prototype,v=function(r,e,o){return new s(r,e,o)};return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(r,e,o){return o||(r=u(r)),navigator.msSaveOrOpenBlob(r,e||"download")}:(l.abort=function(){var r=this;r.readyState=r.DONE,c(r,"abort")},l.readyState=l.INIT=0,l.WRITING=1,l.DONE=2,l.error=l.onwritestart=l.onprogress=l.onwrite=l.onabort=l.onerror=l.onwriteend=null,v)}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);"undefined"!=typeof module&&module.exports?module.exports.saveAs=saveAs:"undefined"!=typeof define&&null!==define&&null!==define.amd&&define([],function(){return saveAs});
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
The MIT License
|
||||||
|
|
||||||
Copyright © 2016 [Eli Grey][1].
|
Copyright © 2016 [Eli Grey][1].
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
|
If you need to save really large files bigger then the blob's size limitation or don't have
|
||||||
|
enough RAM, then have a look at the more advanced [StreamSaver.js][7]
|
||||||
|
that can save data directly to the hard drive asynchronously with the power of the new streams API. That will have
|
||||||
|
support for progress, cancelation and knowing when it's done writing
|
||||||
|
|
||||||
FileSaver.js
|
FileSaver.js
|
||||||
============
|
============
|
||||||
|
|
||||||
FileSaver.js implements the `saveAs()` FileSaver interface in browsers that do
|
|
||||||
not natively support it. There is a [FileSaver.js demo][1] that demonstrates saving
|
|
||||||
various media types.
|
|
||||||
|
|
||||||
FileSaver.js is the solution to saving files on the client-side, and is perfect for
|
FileSaver.js is the solution to saving files on the client-side, and is perfect for
|
||||||
webapps that need to generate files, or for saving sensitive information that shouldn't be
|
web apps that generates files on the client, However if the file is coming from the
|
||||||
sent to an external server.
|
server we recommend you to first try to use [Content-Disposition][8] attachment response header as it has more cross-browser compatible
|
||||||
|
|
||||||
Looking for `canvas.toBlob()` for saving canvases? Check out
|
Looking for `canvas.toBlob()` for saving canvases? Check out
|
||||||
[canvas-toBlob.js][2] for a cross-browser implementation.
|
[canvas-toBlob.js][2] for a cross-browser implementation.
|
||||||
|
|
||||||
Supported browsers
|
Supported Browsers
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
| Browser | Constructs as | Filenames | Max Blob Size | Dependencies |
|
| Browser | Constructs as | Filenames | Max Blob Size | Dependencies |
|
||||||
@@ -27,6 +28,7 @@ Supported browsers
|
|||||||
| Opera < 15 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
|
| Opera < 15 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
|
||||||
| Safari 6.1+* | Blob | No | ? | None |
|
| Safari 6.1+* | Blob | No | ? | None |
|
||||||
| Safari < 6 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
|
| Safari < 6 | data: URI | No | n/a | [Blob.js](https://github.com/eligrey/Blob.js) |
|
||||||
|
| Safari 10.1+ | Blob | Yes | n/a | None |
|
||||||
|
|
||||||
Feature detection is possible:
|
Feature detection is possible:
|
||||||
|
|
||||||
@@ -48,35 +50,55 @@ press <kbd>⌘</kbd>+<kbd>S</kbd> to save the file after it is opened. Using the
|
|||||||
|
|
||||||
### iOS
|
### iOS
|
||||||
|
|
||||||
saveAs must be run within a user interaction event such as onTouchDown or onClick; setTimeout will prevent saveAs from triggering. Due to restrictions in iOS saveAs opens in a new window instead of downloading, if you want this fixed please [tell Apple](https://bugs.webkit.org/show_bug.cgi?id=102914) how this bug is affecting you.
|
saveAs must be run within a user interaction event such as onTouchDown or onClick; setTimeout will prevent saveAs from triggering. Due to restrictions in iOS saveAs opens in a new window instead of downloading, if you want this fixed please [tell Apple how this WebKit bug is affecting you](https://bugs.webkit.org/show_bug.cgi?id=167341).
|
||||||
|
|
||||||
Syntax
|
Syntax
|
||||||
------
|
------
|
||||||
|
### Import saveAs() from file-saver
|
||||||
```js
|
```js
|
||||||
FileSaver saveAs(Blob data, DOMString filename, optional Boolean disableAutoBOM)
|
import saveAs from 'file-saver';
|
||||||
```
|
```
|
||||||
|
|
||||||
Pass `true` for `disableAutoBOM` if you don't want FileSaver.js to automatically provide Unicode text encoding hints (see: [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark)).
|
```js
|
||||||
|
FileSaver saveAs(Blob/File/Url, optional DOMString filename, optional Object { autoBOM })
|
||||||
|
```
|
||||||
|
|
||||||
|
Pass `{ autoBOM: true }` if you want FileSaver.js to automatically provide Unicode text encoding hints (see: [byte order mark](https://en.wikipedia.org/wiki/Byte_order_mark)).
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
### Saving text using require
|
||||||
|
```js
|
||||||
|
var FileSaver = require('file-saver');
|
||||||
|
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
||||||
|
FileSaver.saveAs(blob, "hello world.txt");
|
||||||
|
```
|
||||||
|
|
||||||
### Saving text
|
### Saving text
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
||||||
saveAs(blob, "hello world.txt");
|
FileSaver.saveAs(blob, "hello world.txt");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Saving URLs
|
||||||
|
|
||||||
|
```js
|
||||||
|
FileSaver.saveAs("https://httpbin.org/image", "image.jpg");
|
||||||
|
```
|
||||||
|
Using URLs within the same origin will just use `a[download]`
|
||||||
|
Otherwise, it will first check if it supports cors header with a synchronously head request
|
||||||
|
if it does it will download the data and save it using blob URLs
|
||||||
|
if not it will try to download it using `a[download]`
|
||||||
|
|
||||||
The standard W3C File API [`Blob`][4] interface is not available in all browsers.
|
The standard W3C File API [`Blob`][4] interface is not available in all browsers.
|
||||||
[Blob.js][5] is a cross-browser `Blob` implementation that solves this.
|
[Blob.js][5] is a cross-browser `Blob` implementation that solves this.
|
||||||
|
|
||||||
### Saving a canvas
|
### Saving a canvas
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var canvas = document.getElementById("my-canvas"), ctx = canvas.getContext("2d");
|
var canvas = document.getElementById("my-canvas");
|
||||||
// draw to canvas...
|
|
||||||
canvas.toBlob(function(blob) {
|
canvas.toBlob(function(blob) {
|
||||||
saveAs(blob, "pretty image.png");
|
saveAs(blob, "pretty image.png");
|
||||||
});
|
});
|
||||||
@@ -85,6 +107,21 @@ canvas.toBlob(function(blob) {
|
|||||||
Note: The standard HTML5 `canvas.toBlob()` method is not available in all browsers.
|
Note: The standard HTML5 `canvas.toBlob()` method is not available in all browsers.
|
||||||
[canvas-toBlob.js][6] is a cross-browser `canvas.toBlob()` that polyfills this.
|
[canvas-toBlob.js][6] is a cross-browser `canvas.toBlob()` that polyfills this.
|
||||||
|
|
||||||
|
### Saving File
|
||||||
|
|
||||||
|
You can save a File constructor without specifying a filename. The
|
||||||
|
File itself already contains a name, There is a hand full of ways to get a file
|
||||||
|
instance (from storage, file input, new constructor, clipboard event)
|
||||||
|
But if you still want to change the name, then you can change it in the 2nd argument
|
||||||
|
|
||||||
|
```js
|
||||||