Skip to content

Commit

Permalink
Remove redundant feature detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Alferov committed Jun 26, 2015
1 parent 6c9771c commit 34091ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 30 deletions.
44 changes: 15 additions & 29 deletions src/file-saver.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,59 +13,45 @@

angular
.module('fileSaver', [])
.factory('SaveAs', [SaveAs]);
.factory('SaveAs', SaveAs);

function SaveAs() {
function blobInit(data, type) {
var blob;

if (hasBlobSupport()) {
return new Blob(data, type);
}

blob = new BlobBuilder();
blob.append(data[0]);
blob = getBlob(type.type);

return blob;
}

function isBlobInstance (data) {
return data instanceof Blob || data instanceof BlobBuilder;
return data instanceof Blob;
}

function hasBlobSupport() {
return typeof(Blob) === "function";
function save(blob, filename) {
try {
saveAs(blob, filename);
} catch(err) {
console.error(err.message);
}
}

return {

/**
* saveFile - Immediately starts saving a file, returns undefined.
*
* @param {string|array|object} data Data, represented as a string,
* an array or a Blob object;
* @param {array|Blob} data Represented as an array or a Blob object
* @param {string} filename
* @param {object} options Set of options for the Blob constructor.
* @param {object} options Set of Blob constructor options.
* Optional parameter, if Blob object is passed as first argument
* @return {undefined}
*/

saveFile: function (data, filename, options) {
download: function (data, filename, options) {
var blob;
options = (typeof options === 'undefined') ? {} : options;
data = data instanceof Array ? data : [data];

if (isBlobInstance(data)) {
return saveAs(data, filename);
save(data, filename);
}

data = data instanceof Array ? data : [data];

blob = blobInit(data, options);

return saveAs(blob, filename);
blob = new Blob(data, options);
save(blob, filename);
}

};
}

Expand Down
2 changes: 1 addition & 1 deletion src/file-saver.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34091ef

Please sign in to comment.