P2P Docs
ReferencePrimitives

Hypercore

Secure distributed append-only log for large datasets and realtime streams.

Documented against v11.36.1
stable

Hypercore is a secure, distributed append-only log for sharing large datasets and realtime streams. It supports sparse replication, verified reads, optional block encryption, and session-based workflows for building higher-level local-first and peer-to-peer data structures.

For how Hypercore relates to Hyperblobs and Hyperdrive, see From append-only logs to files.

Install

npm i hypercore

Quickstart

import Hypercore from 'hypercore'

const core = new Hypercore('./my-first-core', { valueEncoding: 'utf-8' })
await core.ready()

await core.append('hello')
await core.append('from hypercore')

console.log('length:', core.length)
console.log('first block:', await core.get(0))
console.log('second block:', await core.get(1))

for await (const block of core.createReadStream()) {
  console.log('streamed:', block)
}

await core.close()

API Reference

Constructors and sessions

Writing and local mutation

Reading, streams, and proofs

Extensions and replication

Storage inspection and mark-and-sweep

Lifecycle and local configuration

Properties

Events

Static helpers

Types

Errors

Coded errors this module can throw — catch them via err.code.

ErrorThrown when
ASSERTIONif index is not a valid block index.; if bytes is not a valid byte offset.; if the start/end range is invalid.; if the provider does not satisfy the HypercoreEncryption interface.; if the core is already in gc mode, or is a named or atomic session.
BAD_ARGUMENTif an appended block exceeds the maximum suggested block size.
INVALID_OPERATIONif the append is inconsistent with the manifest prologue.; if the truncation would break the manifest prologue.; if no database batch was passed, or the tree changed during the batch.
SESSION_CLOSEDif called on a core that is already closing.; if the core has been closed.
SESSION_NOT_WRITABLEif the core is not writable.

See also

On this page