Skip to content

Commit

Permalink
Breaking: drop support of abstract-level 1
Browse files Browse the repository at this point in the history
Follow-up for #18.

Category: removal
  • Loading branch information
vweevers committed Dec 20, 2024
1 parent e3614fb commit d29bcef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This document describes breaking changes and how to upgrade. For a complete list of changes including minor and patch releases, please refer to the [changelog](CHANGELOG.md).

## 2.0.0

Drops support of `abstract-level` 1 (and its callback API) as well as Node.js < 18. Stick with `level-read-stream` 1 if you need to support both `abstract-level` 1 and 2.

## 1.0.0

If you are migrating from `levelup` or `level <= 7` to an [`abstract-level`](https://github.com/Level/abstract-level) database, that database will no longer have stream methods. If you previously did:
Expand Down
32 changes: 8 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const { Readable } = require('readable-stream')

const kIterator = Symbol('iterator')
const kPromises = Symbol('promises')
const kNextv = Symbol('nextv')
const kNextvLegacy = Symbol('nextvLegacy')
const kDestroy = Symbol('destroy')
Expand All @@ -22,11 +21,6 @@ class LevelReadStream extends Readable {
this[kNextv] = this[kNextv].bind(this)
this[kNextvLegacy] = this[kNextvLegacy].bind(this)
this[kDestroy] = this.destroy.bind(this)

// Detect abstract-level 2 by the presence of hooks. Version 2 doesn't
// support callbacks anymore. Version 1 does also support promises but
// that would be slower because it works by wrapping the callback API.
this[kPromises] = db.hooks !== undefined
}

get db () {
Expand All @@ -36,14 +30,10 @@ class LevelReadStream extends Readable {
_read (size) {
if (this.destroyed) return

if (this[kPromises]) {
this[kIterator].nextv(size).then(
this[kNextv],
this[kDestroy]
)
} else {
this[kIterator].nextv(size, this[kNextvLegacy])
}
this[kIterator].nextv(size).then(
this[kNextv],
this[kDestroy]
)
}

[kNextvLegacy] (err, items) {
Expand Down Expand Up @@ -72,16 +62,10 @@ class LevelReadStream extends Readable {
}

_destroy (err, callback) {
if (this[kPromises]) {
this[kIterator].close().then(
err ? () => callback(err) : callback,
callback
)
} else {
this[kIterator].close(function (err2) {
callback(err || err2)
})
}
this[kIterator].close().then(
err ? () => callback(err) : callback,
callback
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"readable-stream": "^4.6.0"
},
"peerDependencies": {
"abstract-level": ">=1.0.0"
"abstract-level": ">=2.0.0"
},
"peerDependenciesMeta": {
"abstract-level": {
Expand Down

0 comments on commit d29bcef

Please sign in to comment.