Bug 1571342 - unify save paths for console and netmonitor and fix the latter to not do docshell loads, r=Honza,nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D41858
This commit is contained in:
Gijs Kruitbosch
2019-08-16 11:13:24 +00:00
parent efe71ddfe3
commit 3614343935
9 changed files with 31 additions and 130 deletions

View File

@@ -781,21 +781,25 @@ exports.openFileStream = function(filePath) {
};
/**
* Open the file at the given path for writing.
* Save the given data to disk after asking the user where to do so.
*
* @param {String} filePath
* @param {Window} parentWindow
* The parent window to use to display the filepicker.
* @param {UInt8Array} dataArray
* The data to write to the file.
* @param {String} fileName
* The suggested filename.
*/
exports.saveFileStream = function(filePath, istream) {
return new Promise((resolve, reject) => {
const ostream = FileUtils.openSafeFileOutputStream(filePath);
NetUtil.asyncCopy(istream, ostream, status => {
if (!components.isSuccessCode(status)) {
reject(new Error(`Could not save "${filePath}"`));
return;
}
FileUtils.closeSafeFileOutputStream(ostream);
resolve();
});
exports.saveAs = async function(parentWindow, dataArray, fileName = "") {
let returnFile;
try {
returnFile = await exports.showSaveFileDialog(parentWindow, fileName);
} catch (ex) {
return;
}
await OS.File.writeAtomic(returnFile.path, dataArray, {
tmpPath: returnFile.path + ".tmp",
});
};