Creates a new Hyperdrive instance. store must be an instance of Corestore.
By default it uses the core at { name: 'db' } from store, unless you set the public key.
await drive.ready()
Waits until internal state is loaded.
Use it once before reading synchronous properties like drive.discoveryKey, unless you called any of the other APIs.
await drive.close()
Fully close this drive, including its underlying Hypercore backed datastructures.
drive.corestore
The Corestore instance used as storage.
drive.db
The underlying Hyperbee backing the drive file structure.
drive.core
The Hypercore used for drive.db.
drive.id
String containing the id (z-base-32 of the public key) identifying this drive.
drive.key
The public key of the Hypercore backing the drive.
drive.discoveryKey
The hash of the public key of the Hypercore backing the drive.
Can be used as a topic to seed the drive using Hyperswarm.
drive.contentKey
The public key of the Hyperblobs instance holding blobs associated with entries in the drive.
drive.writable
Boolean indicating if we can write or delete data in this drive.
drive.readable
Boolean indicating if we can read from this drive. After closing the drive this will be false.
drive.version
Number that indicates how many modifications were made, useful as a version identifier.
drive.supportsMetadata
Boolean indicating if the drive handles or not metadata. Always true.
await drive.put(path, buffer, [options])
Creates a file at path in the drive. options are the same as in createWriteStream.
const buffer = await drive.get(path, [options])
Returns the blob at path in the drive. If no blob exists, returns null.
It also returns null for symbolic links.
options include:
{ wait: true, // Wait for block to be downloaded timeout: 0 // Wait at max some milliseconds (0 means no timeout)}
const entry = await drive.entry(path, [options])
Returns the entry at path in the drive. It looks like this:
{ seq: Number, key: String, value: { executable: Boolean, // Whether the blob at path is an executable linkname: null, // If entry not symlink, otherwise a string to the entry this links to blob: { // Hyperblobs id that can be used to fetch the blob associated with this entry blockOffset: Number, blockLength: Number, byteOffset: Number, byteLength: Number }, metadata: null }}
options include:
{ follow: false, // Follow symlinks, 16 max or throws an error wait: true, // Wait for block to be downloaded timeout: 0 // Wait at max some milliseconds (0 means no timeout)}
const exists = await drive.exists(path)
Returns true if the entry at path does exists, otherwise false.
await drive.del(path)
Deletes the file at path from the drive.
const comparison = drive.compare(entryA, entryB)
Returns 0 if entries are the same, 1 if entryA is older, and -1 if entryB is older.
Deletes the blob from storage to free up space, but the file structure reference is kept.
options include:
{ diff: false // Returned `cleared` bytes object is null unless you enable this}
const cleared = await drive.clearAll([options])
Deletes all the blobs from storage to free up space, similar to how drive.clear() works.
options include:
{ diff: false // Returned `cleared` bytes object is null unless you enable this}
await drive.truncate(version, [options] })
Truncates the Hyperdrive to a previous version (both the file-structure reference and the blobs).
A blobs: <length> option can be passed in if you know the corresponding blobs length, but it is recommended to let the method figure it out for you.
await drive.purge()
Purge both cores (db and blobs) from your storage, completely removing all the drive's data.
await drive.symlink(path, linkname)
Creates an entry in drive at path that points to the entry at linkname.
If a blob entry currently exists at path then it will get overwritten and drive.get(key) will return null, while drive.entry(key) will return the entry with symlink information.
const batch = drive.batch()
Useful for atomically mutate the drive, has the same interface as Hyperdrive.
await batch.flush()
Commit a batch of mutations to the underlying drive.
const stream = drive.list(folder, [options])
Returns a stream of all entries in the drive at paths prefixed with folder.
options include:
{ recursive: true | false // Whether to descend into all subfolders or not, ignore: String || Array // Ignore files and folders by name, wait: true, // Wait for block to be downloaded.}
const stream = drive.readdir(folder, [options])
Returns a stream of all subpaths of entries in drive stored at paths prefixed by folder.
Returns a stream to read out the blob stored in the drive at path.
options include:
{ start: Number, // `start` and `end` are inclusive end: Number, length: Number, // `length` overrides `end`, they're not meant to be used together wait: true, // Wait for blocks to be downloaded timeout: 0 // Wait at max some milliseconds (0 means no timeout)}
Downloads the blobs corresponding to all entries in the drive at paths prefixed with folder. Returns a Download object that resolves once all data has been downloaded:
Downloads all the blobs in folder corresponding to entries in drive.checkout(version) that are not in drive.version. Returns a Download object that resolves once all data has been downloaded:
You can also cancel an ongoing download using destroy().
download.destroy()
In other words, downloads all the blobs added to folder up to version of the drive.
await drive.downloadRange(dbRanges, blobRanges)
Downloads the entries and blobs stored in the rangesdbRanges and blobRanges. Returns a Download object that resolves once all data has been downloaded: