hypercore-storage 0.0.24 → 0.0.25

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/index.js CHANGED
@@ -263,12 +263,9 @@ class ReadBatch {
263
263
  }
264
264
 
265
265
  module.exports = class CoreStorage {
266
- constructor (dir, { autoClose = true } = {}) {
266
+ constructor (dir) {
267
267
  this.db = new RocksDB(dir)
268
268
  this.mutex = new RW()
269
- this.autoClose = !!autoClose
270
-
271
- this.sessions = 0
272
269
  }
273
270
 
274
271
  // just a helper to make tests easier
@@ -401,11 +398,6 @@ module.exports = class CoreStorage {
401
398
  this.mutex.write.unlock()
402
399
  }
403
400
  }
404
-
405
- _onclose () {
406
- if (--this.sessions > 0 || !this.autoClose) return Promise.resolve()
407
- return this.close()
408
- }
409
401
  }
410
402
 
411
403
  class HypercoreStorage {
@@ -415,8 +407,6 @@ class HypercoreStorage {
415
407
  this.dbSnapshot = snapshot
416
408
  this.mutex = root.mutex
417
409
 
418
- this.root.sessions++
419
-
420
410
  this.discoveryKey = discoveryKey
421
411
 
422
412
  this.dependencies = []
@@ -425,7 +415,7 @@ class HypercoreStorage {
425
415
  this.corePointer = core
426
416
  this.dataPointer = data
427
417
 
428
- this.closed = false
418
+ this.destroyed = false
429
419
  }
430
420
 
431
421
  get snapshotted () {
@@ -486,30 +476,30 @@ class HypercoreStorage {
486
476
  }
487
477
 
488
478
  snapshot () {
489
- assert(this.closed === false)
479
+ assert(this.destroyed === false)
490
480
  return new HypercoreStorage(this.root, this.discoveryKey, this.corePointer, this.dataPointer, this.db.snapshot())
491
481
  }
492
482
 
493
483
  createReadBatch (opts) {
494
- assert(this.closed === false)
484
+ assert(this.destroyed === false)
495
485
 
496
486
  const snapshot = this.dbSnapshot
497
487
  return new ReadBatch(this, this.db.read({ snapshot }))
498
488
  }
499
489
 
500
490
  createWriteBatch () {
501
- assert(this.closed === false)
491
+ assert(this.destroyed === false)
502
492
 
503
493
  return new WriteBatch(this, this.db.write())
504
494
  }
505
495
 
506
496
  createBlockStream (opts = {}) {
507
- assert(this.closed === false)
497
+ assert(this.destroyed === false)
508
498
  return createStream(this, createBlockStream, opts)
509
499
  }
510
500
 
511
501
  createUserDataStream (opts = {}) {
512
- assert(this.closed === false)
502
+ assert(this.destroyed === false)
513
503
 
514
504
  const r = encodeIndexRange(this.dataPointer, DATA.USER_DATA, this.dbSnapshot, opts)
515
505
  const s = this.db.iterator(r)
@@ -518,7 +508,7 @@ class HypercoreStorage {
518
508
  }
519
509
 
520
510
  createTreeNodeStream (opts = {}) {
521
- assert(this.closed === false)
511
+ assert(this.destroyed === false)
522
512
 
523
513
  const r = encodeIndexRange(this.dataPointer, DATA.TREE, this.dbSnapshot, opts)
524
514
  const s = this.db.iterator(r)
@@ -527,7 +517,7 @@ class HypercoreStorage {
527
517
  }
528
518
 
529
519
  createBitfieldPageStream (opts = {}) {
530
- assert(this.closed === false)
520
+ assert(this.destroyed === false)
531
521
 
532
522
  const r = encodeIndexRange(this.dataPointer, DATA.BITFIELD, this.dbSnapshot, opts)
533
523
  const s = this.db.iterator(r)
@@ -536,7 +526,7 @@ class HypercoreStorage {
536
526
  }
537
527
 
538
528
  async peekLastTreeNode () {
539
- assert(this.closed === false)
529
+ assert(this.destroyed === false)
540
530
 
541
531
  const last = await this.db.peek(encodeIndexRange(this.dataPointer, DATA.TREE, this.dbSnapshot, { reverse: true }))
542
532
  if (last === null) return null
@@ -544,7 +534,7 @@ class HypercoreStorage {
544
534
  }
545
535
 
546
536
  async peekLastBitfieldPage () {
547
- assert(this.closed === false)
537
+ assert(this.destroyed === false)
548
538
 
549
539
  const last = await this.db.peek(encodeIndexRange(this.dataPointer, DATA.BITFIELD, this.dbSnapshot, { reverse: true }))
550
540
  if (last === null) return null
@@ -552,18 +542,11 @@ class HypercoreStorage {
552
542
  }
553
543
 
554
544
  destroy () {
555
- if (this.dbSnapshot === null) return
556
- this.dbSnapshot.destroy()
557
- }
558
-
559
- close () {
560
- if (this.closed) return Promise.resolve()
561
- this.closed = true
545
+ if (this.destroyed) return
546
+ this.destroyed = true
562
547
 
563
548
  if (this.dbSnapshot) this.dbSnapshot.destroy()
564
549
  this.dbSnapshot = null
565
-
566
- return this.root._onclose()
567
550
  }
568
551
  }
569
552
 
@@ -75,9 +75,7 @@ class MemoryOverlay {
75
75
  return (page && (!disk || index > disk.index)) ? { index, page } : disk
76
76
  }
77
77
 
78
- close () {
79
- return Promise.resolve()
80
- }
78
+ destroy () {}
81
79
 
82
80
  merge (overlay) {
83
81
  if (overlay.head !== null) this.head = overlay.head
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",