corestore 7.0.9 → 7.0.10

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 +25 -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,25 @@
1
+ const auditCore = require('hypercore/lib/audit.js')
2
+
3
+ module.exports = async function audit (store, { dryRun = false } = {}) {
4
+ const stats = { cores: 0, skipped: 0, rootless: 0, dropped: 0 }
5
+
6
+ for await (const { discoveryKey } of store.storage.createCoreStream()) {
7
+ stats.cores++
8
+
9
+ const core = await store.get({ discoveryKey, active: false })
10
+ await core.ready()
11
+
12
+ const audit = await auditCore(core.core, { dryRun })
13
+
14
+ if (audit === null || audit.corrupt) {
15
+ stats.rootless++
16
+ continue
17
+ }
18
+
19
+ if (audit.droppedTreeNodes || audit.droppedBlocks || audit.droppedBits) {
20
+ stats.dropped++
21
+ }
22
+ }
23
+
24
+ return stats
25
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "7.0.9",
3
+ "version": "7.0.10",
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",