hypercore-storage 1.17.0 → 1.18.0

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 +11 -3
  2. package/package.json +5 -3
package/index.js CHANGED
@@ -426,6 +426,9 @@ class CorestoreStorage {
426
426
  this.path = storage !== null ? storage : path.join(db.path, '..')
427
427
  this.readOnly = !!opts.readOnly
428
428
  this.allowBackup = !!opts.allowBackup
429
+ this.deviceFile = null
430
+ this.wait = !!opts.wait
431
+ this.lock = !!opts.lock || this.wait
429
432
 
430
433
  // tmp sync fix for simplicty since not super deployed yet
431
434
  if (this.bootstrap && !this.readOnly) tmpFixStorage(this.path)
@@ -539,9 +542,13 @@ class CorestoreStorage {
539
542
  if (this.bootstrap && !this.readOnly && !this.allowBackup) {
540
543
  const corestoreFile = path.join(this.path, 'CORESTORE')
541
544
 
542
- if (!(await DeviceFile.resume(corestoreFile, { id: this.id }))) {
543
- await DeviceFile.create(corestoreFile, { id: this.id })
544
- }
545
+ this.deviceFile = new DeviceFile(corestoreFile, {
546
+ wait: this.wait,
547
+ lock: this.lock,
548
+ data: { id: this.id }
549
+ })
550
+
551
+ await this.deviceFile.ready()
545
552
  }
546
553
 
547
554
  const rx = new CorestoreRX(this.db, view)
@@ -688,6 +695,7 @@ class CorestoreStorage {
688
695
  await this._flush()
689
696
  await this.db.close()
690
697
  await this.rocks.close()
698
+ if (this.deviceFile) await this.deviceFile.close()
691
699
  }
692
700
 
693
701
  async clear() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",
@@ -10,7 +10,8 @@
10
10
  ],
11
11
  "scripts": {
12
12
  "format": "prettier --write .",
13
- "test": "prettier --check . && node test/all.js",
13
+ "lint": "prettier --check . && lunte",
14
+ "test": "node test/all.js",
14
15
  "test:bare": "bare test/all.js",
15
16
  "test:generate": "brittle -r test/all.js test/*.js"
16
17
  },
@@ -32,7 +33,7 @@
32
33
  "bare-fs": "^4.0.1",
33
34
  "bare-path": "^3.0.0",
34
35
  "compact-encoding": "^2.16.0",
35
- "device-file": "^1.2.2",
36
+ "device-file": "^2.0.0",
36
37
  "flat-tree": "^1.12.1",
37
38
  "hypercore-crypto": "^3.4.2",
38
39
  "hyperschema": "^1.7.0",
@@ -44,6 +45,7 @@
44
45
  },
45
46
  "devDependencies": {
46
47
  "brittle": "^3.7.0",
48
+ "lunte": "^1.0.2",
47
49
  "prettier": "^3.6.2",
48
50
  "prettier-config-holepunch": "^2.0.0",
49
51
  "test-tmp": "^1.3.1"