From 082b8d6c215d835290b7b1b808cb74831cca3853 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Fri, 1 Jul 2022 19:49:06 +0200 Subject: [PATCH] Breaking: bump readable-stream from 3 to 4 See https://github.com/nodejs/readable-stream. TLDR (because you won't find a changelog): it fast-forwards to Node.js 18 streams and, apart from all the changes between Node.js 10 and 18, drops support of Internet Explorer. --- README.md | 2 +- level-ws.js | 8 +++----- package.json | 2 +- test.js | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bec696c..b32852e 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ ws.end() ### `ws = new WriteStream(db[, options])` -Create a [writable stream](https://nodejs.org/dist/latest-v8.x/docs/api/stream.html#stream_class_stream_writable) that operates in object mode, accepting batch operations to be committed with `db.batch()` on each tick of the Node.js event loop. The optional `options` argument may contain: +Create a [writable stream](https://nodejs.org/dist/latest-v18.x/docs/api/stream.html#stream_class_stream_writable) that operates in object mode, accepting batch operations to be committed with `db.batch()` on each tick of the Node.js event loop. The optional `options` argument may contain: - `type` (string, default: `'put'`): default batch operation type if not set on indididual operations. - `maxBufferLength` (number, default `Infinity`): limit the size of batches. When exceeded, the stream will stop processing writes until the current batch has been committed. diff --git a/level-ws.js b/level-ws.js index db6e60d..d02e802 100644 --- a/level-ws.js +++ b/level-ws.js @@ -8,7 +8,9 @@ class WriteStream extends Writable { super({ objectMode: true, - highWaterMark: options.highWaterMark || 16 + highWaterMark: options.highWaterMark || 16, + autoDestroy: true, + emitClose: true }) this._options = options @@ -17,10 +19,6 @@ class WriteStream extends Writable { this._flushing = false this._maxBufferLength = options.maxBufferLength || Infinity this._flush = this._flush.bind(this) - - this.on('finish', () => { - this.emit('close') - }) } _write (data, enc, next) { diff --git a/package.json b/package.json index 80d9cfb..2d26a78 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "UPGRADING.md" ], "dependencies": { - "readable-stream": "^3.1.0" + "readable-stream": "^4.0.0" }, "devDependencies": { "hallmark": "^4.1.0", diff --git a/test.js b/test.js index f3f4bed..bba28d6 100644 --- a/test.js +++ b/test.js @@ -145,7 +145,7 @@ test('race condition between two flushes', function (t, ctx, done) { const order = monitor(ws) ws.on('close', function () { - t.same(order, ['batch', 'batch', 'close']) + t.same(order, ['batch', 'batch', 'finish', 'close']) ctx.verify(ws, done, [ { key: 'a', value: 'a' },