зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1358846: Part 2 - Allow using file compression with JSONFile.jsm. r=rhelmer
MozReview-Commit-ID: 5lHsZqBGq3E --HG-- extra : rebase_source : 1df59152becd11bd95b97fc94ebca83392c17027 extra : source : cb2518673c56cf3b45e4d4a8f2959191290c00d8
This commit is contained in:
Родитель
c98d2b9f37
Коммит
074f5a19ce
|
@ -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));
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче