├── .gitignore ├── LICENSE ├── README.md ├── index.js ├── package.json └── usage.txt /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Mathias Buus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hyperpipe 2 | 3 | Distributed input/output pipe. 4 | 5 | ``` sh 6 | npm install -g hyperpipe 7 | hyperpipe --help 8 | ``` 9 | 10 | ## Usage 11 | 12 | On one computer 13 | 14 | ``` sh 15 | ./program | hyperpipe /tmp/some-folder 16 | 17 | ``` 18 | 19 | On another 20 | 21 | ``` sh 22 | hyperpipe /tmp/some-other-folder 23 | ``` 24 | 25 | ## API 26 | ```sh 27 | Usage: 28 | $ hyperpipe [options] 29 | 30 | Commands: 31 | Pipe a file into the swarm or read from the swarm at a key 32 | 33 | Options: 34 | -h, --help Print usage 35 | -t, --tail Only print get updates 36 | -e, --encoding Set encoding for hypercore (parse ndjson by setting to 'json') 37 | --no-live Exit after hyperpipe is done syncing 38 | 39 | Examples: 40 | $ hyperpipe ./pipe.db < README.md # cat a file & print key 41 | $ hyperpipe ./pipe.db > README.md # write a file from a key 42 | $ tail -F foo.log | hyperpipe ./pipe.db # tail a live log file 43 | $ hyperpipe ./pipe.db --encoding='json' < my-data.json # put ndjson into hypercore 44 | ``` 45 | 46 | ## License 47 | 48 | MIT 49 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var hypercore = require('hypercore') 4 | var swarm = require('hyperdiscovery') 5 | var minimist = require('minimist') 6 | var mkdirp = require('mkdirp') 7 | var path = require('path') 8 | var ndjson = require('ndjson') 9 | var fs = require('fs') 10 | 11 | var usage = fs.readFileSync(path.join(__dirname, 'usage.txt'), 'utf8') 12 | var argv = minimist(process.argv.slice(2), { 13 | alias: {help: 'h', tail: 't', encoding: 'e'}, 14 | boolean: ['help', 'tail', 'no-live'], 15 | default: {'no-live': false} 16 | }) 17 | 18 | if (argv.help) { 19 | console.log(usage) 20 | process.exit() 21 | } 22 | 23 | if (!argv._[0]) { 24 | console.error(usage) 25 | process.exit(1) 26 | } 27 | 28 | mkdirp.sync(argv._[0]) 29 | 30 | var key = argv._[1] 31 | var feed = hypercore(argv._[0], key, {valueEncoding: argv.encoding}) 32 | 33 | feed.on('ready', function () { 34 | if (!feed.writable) { 35 | const opts = { 36 | live: !argv['no-live'], 37 | start: argv.tail ? feed.blocks : 0 38 | } 39 | feed.createReadStream(opts).on('end', onend).pipe(process.stdout) 40 | } else { 41 | console.error(feed.key.toString('hex')) 42 | if (argv.encoding === 'json') { 43 | process.stdin.pipe(ndjson.parse()).pipe(feed.createWriteStream()) 44 | } else { 45 | process.stdin.pipe(feed.createWriteStream()) 46 | } 47 | } 48 | 49 | var sw = swarm(feed) 50 | 51 | function onend () { 52 | sw.close() 53 | } 54 | }) 55 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hyperpipe", 3 | "version": "3.2.0", 4 | "description": "Distributed input/output pipe.", 5 | "main": "index.js", 6 | "dependencies": { 7 | "hypercore": "^6.0.0", 8 | "hyperdiscovery": "^1.1.0", 9 | "minimist": "^1.2.0", 10 | "mkdirp": "^0.5.1", 11 | "ndjson": "^1.5.0" 12 | }, 13 | "devDependencies": { 14 | "standard": "^8.5.0" 15 | }, 16 | "scripts": { 17 | "test": "standard" 18 | }, 19 | "bin": { 20 | "hyperpipe": "./index.js" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/mafintosh/hyperpipe.git" 25 | }, 26 | "author": "Mathias Buus (@mafintosh)", 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/mafintosh/hyperpipe/issues" 30 | }, 31 | "homepage": "https://github.com/mafintosh/hyperpipe" 32 | } 33 | -------------------------------------------------------------------------------- /usage.txt: -------------------------------------------------------------------------------- 1 | Usage: 2 | $ hyperpipe [options] 3 | 4 | Commands: 5 | Pipe a file into the swarm or read from the swarm at a key 6 | 7 | Options: 8 | -h, --help Print usage 9 | -t, --tail Only print get updates 10 | -e, --encoding Set encoding for hypercore (parse ndjson by setting to 'json') 11 | --no-live Exit after hyperpipe is done syncing 12 | 13 | Examples: 14 | $ hyperpipe ./my-pipe < README.md # cat a file & print key 15 | $ hyperpipe ./my-pipe > README.md # write a file from a key 16 | $ tail -F foo.log | hyperpipe ./my-pipe # tail a live log file 17 | $ hyperpipe ./my-pipe --encoding='json' < my-data.json # put ndjson into hypercore 18 | --------------------------------------------------------------------------------