2013-10-23 11:17:36 -04:00
|
|
|
define(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var dl = {};
|
|
|
|
|
2013-11-04 08:20:14 -05:00
|
|
|
dl.createDownload = function(options, callback) {
|
|
|
|
var contentType = options.contentType || 'application/octet-stream';
|
|
|
|
|
2013-10-23 11:17:36 -04:00
|
|
|
chrome.fileSystem.chooseEntry({
|
|
|
|
type: 'saveFile',
|
2013-11-04 08:20:14 -05:00
|
|
|
suggestedName: options.filename
|
|
|
|
}, onEntry);
|
|
|
|
|
|
|
|
function onEntry(file) {
|
2013-10-23 11:17:36 -04:00
|
|
|
if (!file) {
|
2013-11-04 08:20:14 -05:00
|
|
|
callback();
|
2013-10-23 11:17:36 -04:00
|
|
|
return;
|
|
|
|
}
|
2013-11-04 08:20:14 -05:00
|
|
|
file.createWriter(onWriter, onError);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onWriter(writer) {
|
|
|
|
writer.onerror = onError;
|
|
|
|
writer.onwriteend = onEnd;
|
|
|
|
writer.write(new Blob([options.content], {
|
|
|
|
type: contentType
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
function onError(e) {
|
|
|
|
callback({
|
2013-11-14 15:39:20 -05:00
|
|
|
errMsg: 'Error exporting keypair to file!',
|
|
|
|
err: e
|
2013-11-04 08:20:14 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function onEnd() {
|
|
|
|
callback();
|
|
|
|
}
|
2013-10-23 11:17:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return dl;
|
|
|
|
});
|