hypercore 10.15.0 → 10.16.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.
package/README.md CHANGED
@@ -73,6 +73,7 @@ Note that `tree`, `data`, and `bitfield` are normally heavily sparse files.
73
73
  keyPair: kp, // optionally pass the public key and secret key as a key pair
74
74
  encryptionKey: k, // optionally pass an encryption key to enable block encryption
75
75
  onwait: () => {}, // hook that is called if gets are waiting for download
76
+ timeout: 0, // wait at max some milliseconds (0 means no timeout)
76
77
  writable: true // disable appends and truncates
77
78
  }
78
79
  ```
package/lib/core.js CHANGED
@@ -73,7 +73,7 @@ module.exports = class Core {
73
73
  const oplog = new Oplog(oplogFile, {
74
74
  headerEncoding: m.oplog.header,
75
75
  entryEncoding: m.oplog.entry,
76
- headerOnly: opts.readonly
76
+ readonly: opts.readonly
77
77
  })
78
78
 
79
79
  let { header, entries } = await oplog.open()
package/lib/errors.js CHANGED
@@ -44,6 +44,10 @@ module.exports = class HypercoreError extends Error {
44
44
  return new HypercoreError(msg, 'INVALID_PROOF', HypercoreError.INVALID_PROOF)
45
45
  }
46
46
 
47
+ static BLOCK_NOT_AVAILABLE (msg = 'Block is not available') {
48
+ return new HypercoreError(msg, 'BLOCK_NOT_AVAILABLE', HypercoreError.BLOCK_NOT_AVAILABLE)
49
+ }
50
+
47
51
  static SNAPSHOT_NOT_AVAILABLE (msg = 'Snapshot is not available') {
48
52
  return new HypercoreError(msg, 'SNAPSHOT_NOT_AVAILABLE', HypercoreError.SNAPSHOT_NOT_AVAILABLE)
49
53
  }
package/lib/oplog.js CHANGED
@@ -4,11 +4,11 @@ const { crc32 } = require('crc-universal')
4
4
  const { OPLOG_CORRUPT } = require('./errors')
5
5
 
6
6
  module.exports = class Oplog {
7
- constructor (storage, { pageSize = 4096, headerEncoding = cenc.raw, entryEncoding = cenc.raw, headerOnly = false } = {}) {
7
+ constructor (storage, { pageSize = 4096, headerEncoding = cenc.raw, entryEncoding = cenc.raw, readonly = false } = {}) {
8
8
  this.storage = storage
9
9
  this.headerEncoding = headerEncoding
10
10
  this.entryEncoding = entryEncoding
11
- this.headerOnly = headerOnly
11
+ this.readonly = readonly
12
12
  this.flushed = false
13
13
  this.byteLength = 0
14
14
  this.length = 0
@@ -102,8 +102,6 @@ module.exports = class Oplog {
102
102
 
103
103
  result.header = header ? h2.message : h1.message
104
104
 
105
- if (this.headerOnly) return result
106
-
107
105
  while (true) {
108
106
  const entry = this._decodeEntry(state, this.entryEncoding)
109
107
  if (!entry) break
@@ -125,6 +123,7 @@ module.exports = class Oplog {
125
123
  if (size === buffer.byteLength) return result
126
124
 
127
125
  await new Promise((resolve, reject) => {
126
+ if (this.readonly) return resolve()
128
127
  this.storage.truncate(size, err => {
129
128
  if (err) return reject(err)
130
129
  resolve()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.15.0",
3
+ "version": "10.16.0",
4
4
  "description": "Hypercore is a secure, distributed append-only log",
5
5
  "main": "index.js",
6
6
  "scripts": {