_write: function JsonStore__write() { // Don't write if the root is uninitialized or if the store is empty and the // backing file doesn't yet exist. if (!this.isRootInited || (this._isEmpty && !file.exists(this.filename))) return; // If the store is over quota, don't write. The current under-quota state // should persist. if (this.quotaUsage > 1) return; // Finally, write. let stream = file.open(this.filename, "w"); try { stream.writeAsync(JSON.stringify(this.root), function writeAsync(err) { if (err) console.error("Error writing simple storage file: " + this.filename); else if (this.onWrite) this.onWrite(this); }.bind(this)); } catch (err) { // writeAsync closes the stream after it's done, so only close on error. stream.close(); } }
exports.createTemporaryFileFromData = function (data, tmpName) { var profileDir = require("system").pathFor("ProfD"); var path = file.join(profileDir, tmpName ? tmpName : "tmp-file"); var tmpFile = file.open(path, "wb"); tmpFile.write(data); tmpFile.close(); return path; }