corestore 7.0.9 → 7.0.11

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 (3) hide show
  1. package/index.js +6 -0
  2. package/lib/audit.js +23 -0
  3. package/package.json +3 -2
package/index.js CHANGED
@@ -6,6 +6,8 @@ const sodium = require('sodium-universal')
6
6
  const crypto = require('hypercore-crypto')
7
7
  const ID = require('hypercore-id-encoding')
8
8
 
9
+ const auditStore = require('./lib/audit.js')
10
+
9
11
  const [NS] = crypto.namespace('corestore', 1)
10
12
  const DEFAULT_NAMESPACE = b4a.alloc(32) // This is meant to be 32 0-bytes
11
13
 
@@ -211,6 +213,10 @@ class Corestore extends ReadyResource {
211
213
  }
212
214
  }
213
215
 
216
+ audit (opts = {}) {
217
+ return auditStore(this, opts)
218
+ }
219
+
214
220
  suspend () {
215
221
  return this.storage.db.suspend()
216
222
  }
package/lib/audit.js ADDED
@@ -0,0 +1,23 @@
1
+ module.exports = async function audit (store, { dryRun = false } = {}) {
2
+ const stats = { cores: 0, skipped: 0, rootless: 0, dropped: 0 }
3
+
4
+ for await (const { discoveryKey } of store.storage.createCoreStream()) {
5
+ stats.cores++
6
+
7
+ const core = await store.get({ discoveryKey, active: false })
8
+ await core.ready()
9
+
10
+ const audit = await core.core.audit({ dryRun })
11
+
12
+ if (audit === null || audit.corrupt) {
13
+ stats.rootless++
14
+ continue
15
+ }
16
+
17
+ if (audit.droppedTreeNodes || audit.droppedBlocks || audit.droppedBits) {
18
+ stats.dropped++
19
+ }
20
+ }
21
+
22
+ return stats
23
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "7.0.9",
3
+ "version": "7.0.11",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "files": [
7
- "index.js"
7
+ "index.js",
8
+ "lib/*"
8
9
  ],
9
10
  "dependencies": {
10
11
  "b4a": "^1.6.7",