hypercore 10.38.1 → 11.0.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
@@ -23,6 +23,11 @@ Version 10 is not compatible with earlier versions (9 and earlier), but is consi
23
23
  npm install hypercore
24
24
  ```
25
25
 
26
+ > [!NOTE]
27
+ > This readme reflects Hypercore 11, our latest major version that is backed by RocksDB for storage and atomicity.
28
+ > Whilst we are fully validating that, the npm dist-tag for latest is set to latest version of Hypercore 10, the previous major, to avoid too much disruption.
29
+ > It will be updated to 11 in a few weeks.
30
+
26
31
  ## API
27
32
 
28
33
  #### `const core = new Hypercore(storage, [key], [options])`
@@ -35,31 +40,9 @@ Make a new Hypercore instance.
35
40
  const core = new Hypercore('./directory') // store data in ./directory
36
41
  ```
37
42
 
38
- Alternatively you can pass a function instead that is called with every filename Hypercore needs to function and return your own [abstract-random-access](https://github.com/random-access-storage/abstract-random-access) instance that is used to store the data.
39
-
40
- ``` js
41
- const RAM = require('random-access-memory')
42
- const core = new Hypercore((filename) => {
43
- // filename will be one of: data, bitfield, tree, signatures, key, secret_key
44
- // the data file will contain all your data concatenated.
45
-
46
- // just store all files in ram by returning a random-access-memory instance
47
- return new RAM()
48
- })
49
- ```
50
-
51
- Per default Hypercore uses [random-access-file](https://github.com/random-access-storage/random-access-file). This is also useful if you want to store specific files in other directories.
43
+ Alternatively you can pass a [Hypercore Storage](https://github.com/holepunchto/hypercore-storage) or use a [Corestore](https://github.com/holepunchto/corestore) if you want to make many Hypercores efficiently.
52
44
 
53
- Hypercore will produce the following files:
54
-
55
- * `oplog` - The internal truncating journal/oplog that tracks mutations, the public key and other metadata.
56
- * `tree` - The Merkle Tree file.
57
- * `bitfield` - The bitfield of which data blocks this core has.
58
- * `data` - The raw data of each block.
59
-
60
- Note that `tree`, `data`, and `bitfield` are normally heavily sparse files.
61
-
62
- `key` can be set to a Hypercore public key. If you do not set this the public key will be loaded from storage. If no key exists a new key pair will be generated.
45
+ `key` can be set to a Hypercore key which is a hash of Hypercore's internal auth manifest, describing how to validate the Hypercore. If you do not set this, it will be loaded from storage. If nothing is previously stored, a new auth manifest will be generated giving you local write access to it.
63
46
 
64
47
  `options` include:
65
48
 
@@ -79,7 +62,7 @@ Note that `tree`, `data`, and `bitfield` are normally heavily sparse files.
79
62
  }
80
63
  ```
81
64
 
82
- You can also set valueEncoding to any [abstract-encoding](https://github.com/mafintosh/abstract-encoding) or [compact-encoding](https://github.com/compact-encoding) instance.
65
+ You can also set valueEncoding to any [compact-encoding](https://github.com/compact-encoding) instance.
83
66
 
84
67
  valueEncodings will be applied to individual blocks, even if you append batches. If you want to control encoding at the batch-level, you can use the `encodeBatch` option, which is a function that takes a batch and returns a binary-encoded batch. If you provide a custom valueEncoding, it will not be applied prior to `encodeBatch`.
85
68
 
@@ -255,10 +238,6 @@ Truncate the core to a smaller length.
255
238
  Per default this will update the fork id of the core to `+ 1`, but you can set the fork id you prefer with the option.
256
239
  Note that the fork id should be monotonely incrementing.
257
240
 
258
- #### `await core.purge()`
259
-
260
- Purge the hypercore from your storage, completely removing all data.
261
-
262
241
  #### `const hash = await core.treeHash([length])`
263
242
 
264
243
  Get the Merkle Tree hash of the core at a given length, defaulting to the current length of the core.
@@ -305,7 +284,7 @@ To cancel downloading a range simply destroy the range instance.
305
284
  range.destroy()
306
285
  ```
307
286
 
308
- #### `const session = await core.session([options])`
287
+ #### `const session = core.session([options])`
309
288
 
310
289
  Creates a new Hypercore instance that shares the same underlying core.
311
290
 
@@ -315,6 +294,10 @@ Options are inherited from the parent instance, unless they are re-set.
315
294
 
316
295
  `options` are the same as in the constructor.
317
296
 
297
+ #### `const snapshot = core.snapshot([options])`
298
+
299
+ Same as above, but backed by a storage snapshot so will not truncate nor append.
300
+
318
301
  #### `const info = await core.info([options])`
319
302
 
320
303
  Get information about this core, such as its total size in bytes.