hypersource-client
Simple client to talk to HyperSource endpoints
Installation
$ npm install hypersource-client
Usage
The hypersource client can be used from the command line are directly in module code.
Command Line
The following will send an input hyper{core,drive,db,trie}
or DAT
archive to an point and output the response into output-directory/
.
$ hsurl ws://endpoint.com -i /path/to/hyper{core,drive,db,trie} -o output-directory
Programmatic
const hypercore = const hsurl = const ram = const host = `ws://domain.com`const req = const client = // append buffer to request feedreq { res}
Example
Below is an example of a hypersource server that echos a hyperdrive back to the client and the exits.
const hypersource = const hyperdrive = const mirror = const hsurl = const pump = const path = const ram = const bundle = const server = server { const source = const echo = source { source } { const src = fs: source name: '/' const dst = fs: echo name: '/' } { if err console res else echo }} { if err throw err bundle} { if err throw err const client = client} { if err console else res }
API
client = require('hypersource-client')(hyperObject, opts)
Create a client request with a hypercore or hyper*
like object (hypercore
,
hyperdrive
, hypertrie
, hyperdb
, etc...) where opts
can be a
string
that represents the WebSocket endpoint to connect to or an
object that may look like:
endpoint: String // the WebSocket endpoint to connect to (eg: ws://domain.com timeout: Number // A timeout in milliseconds for the underlying hypercore protocol stream. Defaults to '30000' discovery: Object | Boolean // Options passed directly to 'hyperdiscovery'. Set to 'false' to disable
const client = feed 'wss://domain.com'
DAT Network
The client will join the DAT network for a given hyper*
object and
attempt to replicate it with the network. This is useful if the input
request hyper*
object lives somewhere else.
client.connect(callback)
Connect to WebSocket server and send request calling
callback(err, res, req, socket)
upon success or failure where:
err
is a possible error that could have occurred while connecting. (Default:null
)res
is ahyper*
like object that is equivalent in type to the inputhyper*
object. If you give the client ahypercore
, you get back ahypercore
as a response object. The same can be said abouthyperdrive
, etcreq
is the inputhyper*
object given as request inputsocket
is the underlying WebSocket backing this connection
client
client.close(callback)
Closes the client and the underlying resources.
client
client.destroy([err])
Destroys the client with an optional err
.
client.on('error', err)
Emitted when an error occurs.
client.on('peer', peer)
Emitted when a peer is discovered from hyperdiscovery.
Command Line API
usage: hsurl [-hDV] [options] <endpoint>
where options can be:
-i, --input Path to storage for input feed
-o, --output Path to storage for output feed
-f, --force Force actions like overwriting a file or directory
-k, --key Public key for storage feed
-t, --type The feed type (eg: hypercore|hyperdrive|hypertrie...) (Default: 'hypercore')
-h, --help Show this message
-D, --debug Enable debug output (DEBUG="hypersource-client")
-V, --version Show program version
--sparse Treat input as sparse input
--latest Treat input (and output) latest (only for hyperdrive|DAT)
--stdin Read request from stdin
--stdout Output response to stdout
--encoding Set input encoding (--stdout) (Default: 'binary')
--utf8 Alias for '--enoding=utf8'
License
MIT