Registry / storage / hypercore-default-storage

hypercore-default-storage

JSON →
library1.1.1jsnpmunverified

Default storage provider for Hypercore, using random-access-file for persistent storage of hypercore feeds. Version 1.1.1 is the latest stable release. This package provides a simple storage factory function that creates random-access-storage instances for Hypercore, handling file locking for bitfield files to prevent parallel writers. It is a small, focused utility specific to the Hypercore ecosystem, commonly used in Hypercore-based applications like Dat-Protocol archives. Release cadence is low as it is a stable dependency.

npm install hypercore-default-storage
INSTALL
IMPORT
SIG · HYPERCORE-DEFAULT-
H
hypercore-default-storage
storagejavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

defaultStorage
const defaultStorage = require('hypercore-default-storage')
import defaultStorage from 'hypercore-default-storage'
This package is CommonJS only. ESM import is not supported; you must use require().

Shows how to create a Hypercore feed with defaultStorage as the storage provider, append data, and read it back.

const defaultStorage = require('hypercore-default-storage') const hypercore = require('hypercore') const storage = name => defaultStorage(name, { directory: './my-data' }) const feed = hypercore(storage) feed.append(Buffer.from('Hello, world!'), (err) => { if (err) throw err feed.get(0, (err, data) => { console.log(data.toString()) // 'Hello, world!' }) })
Debug
Known issues
gotchaThe storage function must return a random-access-storage instance, not a promise or other type.
fix
Ensure the callback provided to hypercore returns the result of calling defaultStorage synchronously.
affects: >=1.0.0
gotchaIf directory option is not provided, it defaults to current working directory, which may lead to unintended file pollution.
fix
Always specify a dedicated directory option.
affects: >=1.0.0
gotchaBitfield files are locked to avoid parallel writers; do not attempt to share storage paths across processes.
fix
Use separate directories for each process.
affects: >=1.0.0
Errors
Common errors & fixes
Error: random-access-file is not installed
Missing peer dependency random-access-file.
fix
Run npm install random-access-file alongside hypercore-default-storage.
TypeError: defaultStorage is not a function
Incorrect import or require path.
fix
Ensure you use require('hypercore-default-storage') correctly.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
random-access-filerequiredUnderlying file storage implementation
Agent activity
26 hits · last 30 days
node
26
Resources
hypercore-default-storage — npm install hypercore-default-storage · libregistry