hypercore 10.37.10 → 10.37.12

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
@@ -11,6 +11,7 @@ const z32 = require('z32')
11
11
  const id = require('hypercore-id-encoding')
12
12
  const safetyCatch = require('safety-catch')
13
13
  const { createTracer } = require('hypertrace')
14
+ const unslab = require('unslab')
14
15
 
15
16
  const Replicator = require('./lib/replicator')
16
17
  const Core = require('./lib/core')
@@ -911,7 +912,12 @@ module.exports = class Hypercore extends EventEmitter {
911
912
  }
912
913
 
913
914
  async _cacheOnResolve (index, req, fork) {
914
- const block = await req
915
+ const resolved = await req
916
+
917
+ // Unslab only when it takes up less then half the slab
918
+ const block = resolved !== null && 2 * resolved.byteLength < resolved.buffer.byteLength
919
+ ? unslab(resolved)
920
+ : resolved
915
921
 
916
922
  if (this.cache && fork === this.core.tree.fork) {
917
923
  this.cache.set(index, Promise.resolve(block))
package/lib/batch.js CHANGED
@@ -301,7 +301,7 @@ module.exports = class HypercoreBatch extends EventEmitter {
301
301
  }
302
302
  }
303
303
 
304
- this._appends.push(...buffers)
304
+ for (const b of buffers) this._appends.push(b)
305
305
 
306
306
  const info = { length: this.length, byteLength: this.byteLength }
307
307
  this.emit('append')
package/lib/messages.js CHANGED
@@ -2,6 +2,7 @@ const c = require('compact-encoding')
2
2
  const b4a = require('b4a')
3
3
  const { DEFAULT_NAMESPACE } = require('./caps')
4
4
  const { INVALID_OPLOG_VERSION } = require('hypercore-errors')
5
+ const unslab = require('unslab')
5
6
 
6
7
  const EMPTY = b4a.alloc(0)
7
8
 
@@ -244,7 +245,7 @@ wire.handshake = {
244
245
  const flags = c.uint.decode(state)
245
246
  return {
246
247
  seeks: (flags & 1) !== 0,
247
- capability: c.fixed32.decode(state)
248
+ capability: unslab(c.fixed32.decode(state))
248
249
  }
249
250
  }
250
251
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.37.10",
3
+ "version": "10.37.12",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {