mirror of
https://github.com/moparisthebest/mail
synced 2024-08-13 16:43:47 -04:00
26 lines
713 B
JavaScript
26 lines
713 B
JavaScript
|
define(function() {
|
||
|
'use strict';
|
||
|
|
||
|
var dl = {};
|
||
|
|
||
|
dl.createDownload = function(content, filename, contentType) {
|
||
|
contentType = contentType || 'application/octet-stream';
|
||
|
chrome.fileSystem.chooseEntry({
|
||
|
type: 'saveFile',
|
||
|
suggestedName: filename
|
||
|
}, function(file) {
|
||
|
if (!file) {
|
||
|
return;
|
||
|
}
|
||
|
file.createWriter(function(writer) {
|
||
|
writer.onerror = console.error;
|
||
|
writer.onwriteend = function() {};
|
||
|
writer.write(new Blob([content], {
|
||
|
type: contentType
|
||
|
}));
|
||
|
}, console.error);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
return dl;
|
||
|
});
|