hypercore 10.0.0-alpha.46 → 10.0.0-alpha.47

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 +22 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -113,6 +113,7 @@ module.exports = class Hypercore extends EventEmitter {
113
113
  indent + ' opened: ' + opts.stylize(this.opened, 'boolean') + '\n' +
114
114
  indent + ' closed: ' + opts.stylize(this.closed, 'boolean') + '\n' +
115
115
  indent + ' snapshotted: ' + opts.stylize(this.snapshotted, 'boolean') + '\n' +
116
+ indent + ' sparse: ' + opts.stylize(this.sparse, 'boolean') + '\n' +
116
117
  indent + ' writable: ' + opts.stylize(this.writable, 'boolean') + '\n' +
117
118
  indent + ' length: ' + opts.stylize(this.length, 'number') + '\n' +
118
119
  indent + ' byteLength: ' + opts.stylize(this.byteLength, 'number') + '\n' +
@@ -182,9 +183,11 @@ module.exports = class Hypercore extends EventEmitter {
182
183
  throw SESSION_CLOSED('Cannot make sessions on a closing core')
183
184
  }
184
185
 
186
+ const sparse = opts.sparse === false ? false : this.sparse
185
187
  const Clz = opts.class || Hypercore
186
188
  const s = new Clz(this.storage, this.key, {
187
189
  ...opts,
190
+ sparse,
188
191
  _opening: this.opening,
189
192
  _sessions: this.sessions
190
193
  })
@@ -324,14 +327,27 @@ module.exports = class Hypercore extends EventEmitter {
324
327
  }
325
328
  }
326
329
 
327
- _updateSnapshot () {
328
- const prev = this._snapshot
329
- const next = this._snapshot = {
330
- length: this.core.tree.length,
331
- byteLength: this.core.tree.byteLength,
330
+ _getSnapshot () {
331
+ if (this.sparse) {
332
+ return {
333
+ length: this.core.tree.length,
334
+ byteLength: this.core.tree.byteLength,
335
+ fork: this.core.tree.fork,
336
+ compatLength: this.core.tree.length
337
+ }
338
+ }
339
+
340
+ return {
341
+ length: this.core.header.contiguousLength,
342
+ byteLength: 0,
332
343
  fork: this.core.tree.fork,
333
- compatLength: this.core.tree.length
344
+ compatLength: this.core.header.contiguousLength
334
345
  }
346
+ }
347
+
348
+ _updateSnapshot () {
349
+ const prev = this._snapshot
350
+ const next = this._snapshot = this._getSnapshot()
335
351
 
336
352
  if (!prev) return true
337
353
  return prev.length !== next.length || prev.fork !== next.fork
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.0.0-alpha.46",
3
+ "version": "10.0.0-alpha.47",
4
4
  "description": "Hypercore 10",
5
5
  "main": "index.js",
6
6
  "scripts": {