@alcalzone/jsonl-db
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -16,2 +16,3 @@ export declare class DB<V extends unknown = unknown> { | ||
private _dumpFd; | ||
private _compressBacklog; | ||
private _writeBacklog; | ||
@@ -18,0 +19,0 @@ private _dumpBacklog; |
@@ -103,3 +103,11 @@ "use strict"; | ||
write(line) { | ||
this._writeBacklog.write(line); | ||
if (this._compressBacklog && !this._compressBacklog.destroyed) { | ||
this._compressBacklog.write(line); | ||
} | ||
else if (this._writeBacklog && !this._writeBacklog.destroyed) { | ||
this._writeBacklog.write(line); | ||
} | ||
else { | ||
throw new Error("Cannot write into the database while no streams are open!"); | ||
} | ||
// If necessary, write to the dump backlog, so the dump doesn't miss any data | ||
@@ -188,3 +196,5 @@ if (this._dumpBacklog && !this._dumpBacklog.destroyed) { | ||
this._closeDBPromise = deferred_promise_1.createDeferredPromise(); | ||
// Disable writing into the backlog stream | ||
// Disable writing into the backlog stream and buffer all writes | ||
// in the compress backlog in the meantime | ||
this._compressBacklog = new stream.PassThrough({ objectMode: true }); | ||
this._writeBacklog.end(); | ||
@@ -197,6 +207,16 @@ this._writeBacklog = undefined; | ||
await fs.unlink(this.filename + ".bak"); | ||
// Start the write thread | ||
// Start the write thread again | ||
this._openPromise = deferred_promise_1.createDeferredPromise(); | ||
void this.writeThread(); | ||
await this._openPromise; | ||
// Write all buffered data | ||
this._compressBacklog.pipe(this._writeBacklog, { | ||
// Don't close the target stream! | ||
end: false, | ||
}); | ||
this._compressBacklog.on("end", () => { | ||
var _a; | ||
(_a = this._compressBacklog) === null || _a === void 0 ? void 0 : _a.destroy(); | ||
this._compressBacklog = undefined; | ||
}); | ||
} | ||
@@ -203,0 +223,0 @@ /** Closes the DB and waits for all data to be written */ |
{ | ||
"name": "@alcalzone/jsonl-db", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Simple JSONL-based key-value store", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
@@ -55,2 +55,5 @@ # jsonl-db | ||
### 0.1.3 (2020-04-25) | ||
* Writes that happen while `compress()` replaces files are now persisted | ||
### 0.1.2 (2020-04-25) | ||
@@ -57,0 +60,0 @@ * `compress()` no longer overwrites the main file while the DB is being closed |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26652
290
67