diff --git a/toolkit/modules/JSONFile.jsm b/toolkit/modules/JSONFile.jsm index e2605ee566bf..b83673e6d145 100644 --- a/toolkit/modules/JSONFile.jsm +++ b/toolkit/modules/JSONFile.jsm @@ -89,6 +89,8 @@ const kSaveDelayMs = 1500; * automatically finalize the file when triggered. Defaults * to `profileBeforeChange`; exposed as an option for * testing. + * - compression: A compression algorithm to use when reading and + * writing the data. */ function JSONFile(config) { this.path = config.path; @@ -105,6 +107,11 @@ function JSONFile(config) { } this._saver = new DeferredTask(() => this._save(), config.saveDelayMs); + this._options = {}; + if (config.compression) { + this._options.compression = config.compression; + } + this._finalizeAt = config.finalizeAt || AsyncShutdown.profileBeforeChange; this._finalizeInternalBound = this._finalizeInternal.bind(this); this._finalizeAt.addBlocker("JSON store: writing data", @@ -175,7 +182,7 @@ JSONFile.prototype = { let data = {}; try { - let bytes = await OS.File.read(this.path); + let bytes = await OS.File.read(this.path, this._options); // If synchronous loading happened in the meantime, exit now. if (this.dataReady) { @@ -285,7 +292,9 @@ JSONFile.prototype = { await Promise.resolve(this._beforeSave()); } await OS.File.writeAtomic(this.path, bytes, - { tmpPath: this.path + ".tmp" }); + Object.assign( + { tmpPath: this.path + ".tmp" }, + this._options)); }, /**