A Node client library and CLI tool for interacting with the Hyperdrive daemon.
Implements the RPC methods defined in the hyperdrive-schemas
repo.
npm i hyperdrive-daemon-client --save
This module provides both programmatic and CLI access to the Hyperdrive daemon. For info about how to use the CLI, take a look at README in the daemon repo.
Each client takes an optional gRPC endpoint and access token as constructor arguments:
const { HyperdriveClient } = require('hyperdrive-daemon-client')
const client = new HyperdriveClient('localhost:3101', 'your_access_token')
If you're running the client and the daemon on the same machine, the endpoint/token can be read from a common location (by default, ~/.hyperdrive
). If the arguments are not provided, then they will be read from this file (which is created by the daemon).
All Hyperdrive API methods are accessed through client.drive
, and all FUSE methods through client.fuse
.
The client exposes a gRPC interface for a) creating and interacting with remote Hyperdrives and b) mounting Hyperdrives as local directories using FUSE.
Check out the daemon tests for more example usage.
The client's Hyperdrive API is designed to mirror the methods in Hyperdrive as closely as possible.
Operations to manage sessions or get more general information about the state of the daemon.
Creates a Hyperdrive using the provided drive options (if one has not previously been created), then opens a session for that drive.
Options can include:
key
: The key of an existing Hyperdriveversion
: The version of the drive (this will create a checkout).hash
: A root tree hash that will be used for validation (Note: currently unimplemented).
Returns:
drive
: A remote Hyperdrive instance that can be used for subsequent drive-specific commands.
Get networking statistics for all drives being actively managed by the daemon. The returned object is a list of stats results of the form described below.
Each of the following is not a Hyperdrive method, but applies only to a single session.
Close a remote drive's underlying session.
_Note: This currently does not close the actual Hyperdrive in the daemon. _
Get networking statistics for a drive.
The returned statistics will be a list of stats per-mount, with top-level statistics contained in the entry for the '/' mount, eg:
[{ path: '/', metadata: { ... }, content: { ... } }, { path: '/a', metadata: { ... }, content: { ... } }, ... ]
Advertise a drive to the discovery network.
Stop advertising a drive to the discovery network.
The client currently only supports a subset of the Hyperdrive API. We're actively working on extending this (targeting complete parity)! Each method's options mirror those in the hyperdrive module.
Each method returns a Promise, but can optionally take a callback (to more accurately reflect the Hyperdrive API).
Method arguments take the same form as those in Hyperdrive. The following methods are supported as of now:
drive.createWriteStream(path, opts)
drive.writeFile(path, content, cb(err))
drive.createReadStream(path, opts)
drive.readFile(path, cb(err, content))
drive.mount(path, mountOpts, cb(err, mountInfo)
drive.unmount(path, cb(err))
drive.readdir(dirName, readdirOpts, cb(err, fileList))
drive.stat(path, cb(err, stat))
drive.watch(path, function onwatch () {})
drive.mkdir(dirName, opts, cb(err)
drive.rmdir(dirName, cb(err)
The client library also provides programmatic access to the daemon's FUSE interface. You can mount/unmount your root drive, or mount and share subdrives:
Mount either the root drive (if /mnt
is not specified), or a subdirectory within the root drive.
mnt
: The mountpoint of the drive (currently enforced to be/hyperdrive
if it's the root drive, and a subdirectory within/hyperdrive/home
otherwise.opts
: Hyperdrive mount options (identical to those in Hyperdrive).
Unmounts either a subdrive, or the root drive if mnt
is not specified.
Advertise the drive mounted at path
to the network.
Stop advertisingthe drive mounted at path
to the network.
MIT