hypercore-storage 0.0.30 → 0.0.31

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.
Files changed (2) hide show
  1. package/index.js +17 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -513,7 +513,7 @@ class HypercoreStorage {
513
513
  createUserDataStream (opts = {}) {
514
514
  assert(this.destroyed === false)
515
515
 
516
- const r = encodeIndexRange(this.dataPointer, DATA.USER_DATA, this.dbSnapshot, opts)
516
+ const r = encodeUserDataRange(this.dataPointer, DATA.USER_DATA, this.dbSnapshot, opts)
517
517
  const s = this.db.iterator(r)
518
518
  s._readableState.map = mapStreamUserData
519
519
  return s
@@ -584,6 +584,8 @@ function mapStreamUserData (data) {
584
584
 
585
585
  const key = c.string.decode(state)
586
586
 
587
+ if (data.value.byteLength === 0) return null
588
+
587
589
  return { key, value: data.value }
588
590
  }
589
591
 
@@ -655,6 +657,20 @@ function encodeIndexRange (pointer, type, snapshot, opts) {
655
657
  return bounded
656
658
  }
657
659
 
660
+ function encodeUserDataRange (pointer, type, snapshot, opts) {
661
+ const bounded = { snapshot, gt: null, gte: null, lte: null, lt: null, reverse: !!opts.reverse, limit: toLimit(opts.limit) }
662
+
663
+ if (opts.gt || opts.gt === 0) bounded.gt = encodeUserDataIndex(pointer, type, opts.gt)
664
+ else if (opts.gte) bounded.gte = encodeUserDataIndex(pointer, type, opts.gte)
665
+ else bounded.gte = encodeDataIndex(pointer, type, 0)
666
+
667
+ if (opts.lt || opts.lt === 0) bounded.lt = encodeUserDataIndex(pointer, type, opts.lt)
668
+ else if (opts.lte) bounded.lte = encodeUserDataIndex(pointer, type, opts.lte)
669
+ else bounded.lte = encodeDataIndex(pointer, type, Infinity)
670
+
671
+ return bounded
672
+ }
673
+
658
674
  function toLimit (n) {
659
675
  return n === 0 ? 0 : (n || Infinity)
660
676
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",