{"id":15497195,"url":"https://github.com/jwerle/hypersource-client","last_synced_at":"2025-07-08T00:33:41.745Z","repository":{"id":57270248,"uuid":"183528599","full_name":"jwerle/hypersource-client","owner":"jwerle","description":"Simple client to talk to HyperSource endpoints","archived":false,"fork":false,"pushed_at":"2019-06-06T16:25:43.000Z","size":36,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-02T05:45:51.589Z","etag":null,"topics":["client","hypercore","hypersource"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwerle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-26T00:30:24.000Z","updated_at":"2021-09-21T19:39:09.000Z","dependencies_parsed_at":"2022-09-02T09:51:15.469Z","dependency_job_id":null,"html_url":"https://github.com/jwerle/hypersource-client","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/jwerle/hypersource-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhypersource-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhypersource-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhypersource-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhypersource-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/hypersource-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fhypersource-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264169172,"owners_count":23567265,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","hypercore","hypersource"],"created_at":"2024-10-02T08:31:36.441Z","updated_at":"2025-07-08T00:33:41.537Z","avatar_url":"https://github.com/jwerle.png","language":"JavaScript","readme":"hypersource-client\n==================\n\nSimple client to talk to HyperSource endpoints\n\n## Installation\n\n```sh\n$ npm install hypersource-client\n```\n\n## Usage\n\nThe hypersource client can be used from the command line are directly in\nmodule code.\n\n### Command Line\n\nThe following will send an input `hyper{core,drive,db,trie}` or `DAT`\narchive to an point and output the response into `output-directory/`.\n\n```sh\n$ hsurl ws://endpoint.com -i /path/to/hyper{core,drive,db,trie} -o output-directory\n```\n\n### Programmatic\n\n```js\nconst hypercore = require('hypercore')\nconst hsurl = require('hypersource-client')\nconst ram = require('random-access-memory')\n\nconst host = `ws://domain.com`\nconst req = hypercore(ram, key, opts)\nconst client = hsurl(req, host).connnect(onconnect)\n\n// append buffer to request feed\nreq.append('hello')\n\nfunction onconnect(err, res) {\n  res.head(console.log)\n}\n```\n\n## Example\n\nBelow is an example of a\n[hypersource](https://github.com/jwerle/hypersource) server that echos\na [hyperdrive](https://github.com/mafintosh/hyperdrive) back to the\nclient and the exits.\n\n```js\nconst hypersource = require('hypersource')\nconst hyperdrive = require('hyperdrive')\nconst mirror = require('mirror-folder')\nconst hsurl = require('hypersource-client')\nconst pump = require('pump')\nconst path = require('path')\nconst ram = require('random-access-memory')\n\nconst bundle = hyperdrive(ram)\nconst server = hypersource(onrequest)\n\nserver.listen(3000, onlistening)\n\nfunction onrequest(req, res) {\n  const source = hyperdrive(ram, req.key, req)\n  const echo = hyperdrive(ram, res.key, res)\n\n  source.replicate(req).once('handshake', onhandshake)\n\n  function onhandshake() {\n    source.once('update', onupdate)\n  }\n\n  function onupdate() {\n    const src = { fs: source, name: '/' }\n    const dst = { fs: echo, name: '/' }\n    mirror(src, dst, onmirror)\n  }\n\n  function onmirror(err) {\n    if (err) {\n      console.error('ERR', err)\n      res.close()\n    } else {\n      echo.replicate(res)\n    }\n  }\n}\n\nfunction onlistening(err) {\n  if (err) {\n    throw err\n  }\n\n  bundle.ready(() =\u003e {\n    bundle.writeFile('hello.txt', 'hello world', onwrite)\n  })\n}\n\nfunction onwrite(err) {\n  if (err) {\n    throw err\n  }\n\n  const client = hsurl(bundle, 'ws://localhost:3000')\n  client.connect(onconnect)\n}\n\nfunction onconnect(err, res, req, socket) {\n  if (err) {\n    console.error('ERR', err)\n  } else {\n    res.once('update', () =\u003e {\n      const index = res.createReadStream('hello.txt')\n\n      index.on('error', (err) =\u003e {\n        console.error('ERR', err)\n      })\n\n      index.on('end', () =\u003e {\n        server.close()\n        process.nextTick(process.exit, 0)\n      })\n\n      index.pipe(process.stdout)\n    })\n  }\n}\n```\n\n## API\n\n### `client = require('hypersource-client')(hyperObject, opts)`\n\nCreate a client request with a hypercore or `hyper*` like object (`hypercore`,\n`hyperdrive`, `hypertrie`, `hyperdb`, etc...) where `opts` can be a\n`string` that represents the WebSocket endpoint to connect to or an\nobject that may look like:\n\n```js\n\n{\n  endpoint: String, // the WebSocket endpoint to connect to (eg: ws://domain.com\n  timeout: Number, // A timeout in milliseconds for the underlying hypercore protocol stream. Defaults to '30000'\n  discovery: Object | Boolean, // Options passed directly to 'hyperdiscovery'. Set to 'false' to disable\n}\n```\n\n```js\nconst client = require('hypersource-client')(feed, 'wss://domain.com')\n```\n\n#### DAT Network\n\nThe client will join the DAT network for a given `hyper*` object and\nattempt to replicate it with the network. This is useful if the input\nrequest `hyper*` object lives somewhere else.\n\n#### `client.connect(callback)`\n\nConnect to WebSocket server and send request calling\n`callback(err, res, req, socket)` upon success or failure where:\n\n* `err` is a possible error that could have occurred while connecting.\n  (Default: `null`)\n* `res` is a `hyper*` like object that is equivalent in type to the\n  input `hyper*` object. If you give the client a `hypercore`, you get\n  back a `hypercore` as a response object. The same can be said about\n  `hyperdrive`, etc\n* `req` is the input `hyper*` object given as request input\n* `socket` is the underlying WebSocket backing this connection\n\n```js\nclient.connect((err, res) =\u003e {\n  if (err) {\n    // handle error\n  } else {\n    res.update(() =\u003e { // asumes hypercore given\n      res.head(console.log)\n    })\n  }\n})\n```\n\n#### `client.close(callback)`\n\nCloses the client and the underlying resources.\n\n```js\nclient.close((err) =\u003e {\n  if (err) {\n    // handle error while closing client\n  }\n})\n```\n\n#### `client.destroy([err])`\n\nDestroys the client with an optional `err`.\n\n#### `client.on('error', err)`\n\nEmitted when an error occurs.\n\n#### `client.on('peer', peer)`\n\nEmitted when a peer is discovered from\n[hyperdiscovery](https://github.com/karissa/hyperdiscovery).\n\n## Command Line API\n\n```\nusage: hsurl [-hDV] [options] \u003cendpoint\u003e\nwhere options can be:\n\n  -i, --input     Path to storage for input feed\n  -o, --output    Path to storage for output feed\n  -f, --force     Force actions like overwriting a file or directory\n  -k, --key       Public key for storage feed\n  -t, --type      The feed type (eg: hypercore|hyperdrive|hypertrie...) (Default: 'hypercore')\n  -h, --help      Show this message\n  -D, --debug     Enable debug output (DEBUG=\"hypersource-client\")\n  -V, --version   Show program version\n      --sparse    Treat input as sparse input\n      --latest    Treat input (and output) latest (only for hyperdrive|DAT)\n      --stdin     Read request from stdin\n      --stdout    Output response to stdout\n      --encoding  Set input encoding (--stdout) (Default: 'binary')\n      --utf8      Alias for '--enoding=utf8'\n\n```\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fhypersource-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Fhypersource-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fhypersource-client/lists"}