file-saver
Advanced tools
Comparing version 2.0.2 to 2.0.4
@@ -86,9 +86,13 @@ (function (global, factory) { | ||
} | ||
} | ||
} // Detect WebView inside a native macOS app by ruling out all browsers | ||
// We just need to check for 'Safari' because all other browsers (besides Firefox) include that too | ||
// https://www.whatismybrowser.com/guides/the-latest-user-agent/macos | ||
var isMacOSWebView = /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent); | ||
var saveAs = _global.saveAs || ( // probably in some web worker | ||
typeof window !== 'object' || window !== _global ? function saveAs() {} | ||
/* noop */ | ||
// Use download attribute first if possible (#193 Lumia mobile) | ||
: 'download' in HTMLAnchorElement.prototype ? function saveAs(blob, name, opts) { | ||
// Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView | ||
: 'download' in HTMLAnchorElement.prototype && !isMacOSWebView ? function saveAs(blob, name, opts) { | ||
var URL = _global.URL || _global.webkitURL; | ||
@@ -157,3 +161,3 @@ var a = document.createElement('a'); | ||
if ((isChromeIOS || force && isSafari) && typeof FileReader === 'object') { | ||
if ((isChromeIOS || force && isSafari || isMacOSWebView) && typeof FileReader !== 'undefined') { | ||
// Safari doesn't allow downloading of blob URLs | ||
@@ -160,0 +164,0 @@ var reader = new FileReader(); |
@@ -1,3 +0,3 @@ | ||
(function(a,b){if("function"==typeof define&&define.amd)define([],b);else if("undefined"!=typeof exports)b();else{b(),a.FileSaver={exports:{}}.exports}})(this,function(){"use strict";function b(a,b){return"undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(b,c,d){var e=new XMLHttpRequest;e.open("GET",b),e.responseType="blob",e.onload=function(){a(e.response,c,d)},e.onerror=function(){console.error("could not download file")},e.send()}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send()}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"))}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b)}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,a=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href)},4E4),setTimeout(function(){e(j)},0))}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else{var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i)})}}:function(a,b,d,e){if(e=e||open("","_blank"),e&&(e.document.title=e.document.body.innerText="downloading..."),"string"==typeof a)return c(a,b,d);var g="application/octet-stream"===a.type,h=/constructor/i.test(f.HTMLElement)||f.safari,i=/CriOS\/[\d]+/.test(navigator.userAgent);if((i||g&&h)&&"object"==typeof FileReader){var j=new FileReader;j.onloadend=function(){var a=j.result;a=i?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),e?e.location.href=a:location=a,e=null},j.readAsDataURL(a)}else{var k=f.URL||f.webkitURL,l=k.createObjectURL(a);e?e.location=l:location.href=l,e=null,setTimeout(function(){k.revokeObjectURL(l)},4E4)}});f.saveAs=a.saveAs=a,"undefined"!=typeof module&&(module.exports=a)}); | ||
(function(a,b){if("function"==typeof define&&define.amd)define([],b);else if("undefined"!=typeof exports)b();else{b(),a.FileSaver={exports:{}}.exports}})(this,function(){"use strict";function b(a,b){return"undefined"==typeof b?b={autoBom:!1}:"object"!=typeof b&&(console.warn("Deprecated: Expected third argument to be a object"),b={autoBom:!b}),b.autoBom&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(a.type)?new Blob(["\uFEFF",a],{type:a.type}):a}function c(a,b,c){var d=new XMLHttpRequest;d.open("GET",a),d.responseType="blob",d.onload=function(){g(d.response,b,c)},d.onerror=function(){console.error("could not download file")},d.send()}function d(a){var b=new XMLHttpRequest;b.open("HEAD",a,!1);try{b.send()}catch(a){}return 200<=b.status&&299>=b.status}function e(a){try{a.dispatchEvent(new MouseEvent("click"))}catch(c){var b=document.createEvent("MouseEvents");b.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),a.dispatchEvent(b)}}var f="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof global&&global.global===global?global:void 0,a=/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),g=f.saveAs||("object"!=typeof window||window!==f?function(){}:"download"in HTMLAnchorElement.prototype&&!a?function(b,g,h){var i=f.URL||f.webkitURL,j=document.createElement("a");g=g||b.name||"download",j.download=g,j.rel="noopener","string"==typeof b?(j.href=b,j.origin===location.origin?e(j):d(j.href)?c(b,g,h):e(j,j.target="_blank")):(j.href=i.createObjectURL(b),setTimeout(function(){i.revokeObjectURL(j.href)},4E4),setTimeout(function(){e(j)},0))}:"msSaveOrOpenBlob"in navigator?function(f,g,h){if(g=g||f.name||"download","string"!=typeof f)navigator.msSaveOrOpenBlob(b(f,h),g);else if(d(f))c(f,g,h);else{var i=document.createElement("a");i.href=f,i.target="_blank",setTimeout(function(){e(i)})}}:function(b,d,e,g){if(g=g||open("","_blank"),g&&(g.document.title=g.document.body.innerText="downloading..."),"string"==typeof b)return c(b,d,e);var h="application/octet-stream"===b.type,i=/constructor/i.test(f.HTMLElement)||f.safari,j=/CriOS\/[\d]+/.test(navigator.userAgent);if((j||h&&i||a)&&"undefined"!=typeof FileReader){var k=new FileReader;k.onloadend=function(){var a=k.result;a=j?a:a.replace(/^data:[^;]*;/,"data:attachment/file;"),g?g.location.href=a:location=a,g=null},k.readAsDataURL(b)}else{var l=f.URL||f.webkitURL,m=l.createObjectURL(b);g?g.location=m:location.href=m,g=null,setTimeout(function(){l.revokeObjectURL(m)},4E4)}});f.saveAs=g.saveAs=g,"undefined"!=typeof module&&(module.exports=g)}); | ||
//# sourceMappingURL=FileSaver.min.js.map |
{ | ||
"name": "file-saver", | ||
"version": "2.0.2", | ||
"version": "2.0.4", | ||
"description": "An HTML5 saveAs() FileSaver implementation", | ||
@@ -5,0 +5,0 @@ "main": "dist/FileSaver.min.js", |
@@ -1,2 +0,2 @@ | ||
If you need to save really large files bigger then the blob's size limitation or don't have | ||
If you need to save really large files bigger than the blob's size limitation or don't have | ||
enough RAM, then have a look at the more advanced [StreamSaver.js][7] | ||
@@ -92,3 +92,3 @@ that can save data directly to the hard drive asynchronously with the power of the new streams API. That will have | ||
Otherwise, it will first check if it supports cors header with a synchronous head request. | ||
If it does, it will download the data and save using blob URLs. | ||
If it does, it will download the data and save using blob URLs. | ||
If not, it will try to download it using `a[download]`. | ||
@@ -114,3 +114,3 @@ | ||
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). | ||
instance (from storage, file input, new constructor, clipboard event). | ||
If you still want to change the name, then you can change it in the 2nd argument. | ||
@@ -117,0 +117,0 @@ |
@@ -69,2 +69,7 @@ /* | ||
// Detect WebView inside a native macOS app by ruling out all browsers | ||
// We just need to check for 'Safari' because all other browsers (besides Firefox) include that too | ||
// https://www.whatismybrowser.com/guides/the-latest-user-agent/macos | ||
var isMacOSWebView = /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent) | ||
var saveAs = _global.saveAs || ( | ||
@@ -75,4 +80,4 @@ // probably in some web worker | ||
// Use download attribute first if possible (#193 Lumia mobile) | ||
: 'download' in HTMLAnchorElement.prototype | ||
// Use download attribute first if possible (#193 Lumia mobile) unless this is a macOS WebView | ||
: ('download' in HTMLAnchorElement.prototype && !isMacOSWebView) | ||
? function saveAs (blob, name, opts) { | ||
@@ -142,3 +147,3 @@ var URL = _global.URL || _global.webkitURL | ||
if ((isChromeIOS || (force && isSafari)) && typeof FileReader === 'object') { | ||
if ((isChromeIOS || (force && isSafari) || isMacOSWebView) && typeof FileReader !== 'undefined') { | ||
// Safari doesn't allow downloading of blob URLs | ||
@@ -145,0 +150,0 @@ var reader = new FileReader() |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35833
321