hypercore-storage 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/close-error-stream.js +14 -0
- package/lib/view.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const { Readable } = require('streamx')
|
|
2
|
+
|
|
3
|
+
// used for returned a stream that just errors (during read during teardown)
|
|
4
|
+
|
|
5
|
+
module.exports = class CloseErrorStream extends Readable {
|
|
6
|
+
constructor (err) {
|
|
7
|
+
super()
|
|
8
|
+
this.error = err
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
_open (cb) {
|
|
12
|
+
cb(this.error)
|
|
13
|
+
}
|
|
14
|
+
}
|
package/lib/view.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { Readable, getStreamError } = require('streamx')
|
|
2
|
+
const CloseErrorStream = require('./close-error-stream.js')
|
|
2
3
|
const b4a = require('b4a')
|
|
3
4
|
|
|
4
5
|
class OverlayStream extends Readable {
|
|
@@ -212,6 +213,8 @@ class View {
|
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
iterator (db, start, end, reverse) {
|
|
216
|
+
if (dbClosing(db)) return new CloseErrorStream(new Error('RocksDB session is closed'))
|
|
217
|
+
|
|
215
218
|
const stream = db.iterator({ gte: start, lt: end, reverse })
|
|
216
219
|
if (this.changes === null) return stream
|
|
217
220
|
|
|
@@ -344,3 +347,8 @@ function reverseArray (list) {
|
|
|
344
347
|
for (let i = 0; i < list.length; i++) r[r.length - 1 - i] = list[i]
|
|
345
348
|
return r
|
|
346
349
|
}
|
|
350
|
+
|
|
351
|
+
// TODO: expose from rocks instead
|
|
352
|
+
function dbClosing (db) {
|
|
353
|
+
return db._state.closing || db._index === -1
|
|
354
|
+
}
|