-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathangular-file-saver.service.js
42 lines (34 loc) · 1.03 KB
/
angular-file-saver.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
module.exports = function FileSaver(Blob, SaveAs, FileSaverUtils) {
function save(blob, filename, disableAutoBOM) {
try {
SaveAs(blob, filename, disableAutoBOM);
} catch(err) {
FileSaverUtils.handleErrors(err.message);
}
}
return {
/**
* saveAs
* Immediately starts saving a file, returns undefined.
*
* @name saveAs
* @function
* @param {Blob} data A Blob instance
* @param {Object} filename Custom filename (extension is optional)
* @param {Boolean} disableAutoBOM Disable automatically provided Unicode
* text encoding hints
*
* @return {Undefined}
*/
saveAs: function(data, filename, disableAutoBOM) {
if (!FileSaverUtils.isBlobInstance(data)) {
FileSaverUtils.handleErrors('Data argument should be a blob instance');
}
if (!FileSaverUtils.isString(filename)) {
FileSaverUtils.handleErrors('Filename argument should be a string');
}
return save(data, filename, disableAutoBOM);
}
};
};