Skip to content

Commit f4c6656

Browse files
Initial commit
0 parents  commit f4c6656

File tree

8,712 files changed

+726573
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,712 files changed

+726573
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.app-data
2+
node_modules
3+
npm-debug.log
4+
package-lock.json
5+
.DS_Store

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
- 1.2.0
4+
- "sync" and "info" now default to non-live output.
5+
- 1.1.0
6+
- Add "beam" command.
7+
- Drives created by "sync" are now automatically seeded.
8+
- 1.0.0
9+
- Initial release.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Blue Link Labs
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 all
13+
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 THE
21+
SOFTWARE.

README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# NOTE
2+
3+
The CLI is currently mostly out of date, tracking the previous major version of the Hypercore stack.
4+
5+
Check out the individual repos instead, like [Hypercore](https://github.com/hypercore-protocol/hypercore), [Hyperbee](https://github.com/hypercore-protocol/hyperbee), [Hyperbeam](https://github.com/mafintosh/hyperbeam), [Hyperswarm](https://github.com/hyperswarm)
6+
7+
<details><summary>Click to see the CLI README still</summary>
8+
9+
# Hyp
10+
11+
<p>[
12+
<a href="https://www.youtube.com/watch?v=SVk1uIQxOO8" target="_blank">Demo Video</a> |
13+
<a href="#installation">Installation</a> |
14+
<a href="#usage">Usage</a> |
15+
<a href="#overview">Overview</a> |
16+
<a href="https://hypercore-protocol.org/guides/hyp/">Website</a>
17+
]</p>
18+
19+
A CLI for peer-to-peer file sharing (and more) using the [Hypercore Protocol](https://hypercore-protocol.org).
20+
21+
<a href="https://www.youtube.com/watch?v=SVk1uIQxOO8" target="_blank">📺 Watch The Demo Video</a>
22+
23+
## Installation
24+
25+
Requires nodejs 14+
26+
27+
```
28+
npm install -g @hyperspace/cli
29+
```
30+
31+
To start using the network, run:
32+
33+
```
34+
hyp daemon start
35+
```
36+
37+
This will run in the background, sync data for you, until you run:
38+
39+
```
40+
hyp daemon stop
41+
```
42+
43+
## Usage
44+
45+
Command overview:
46+
47+
```bash
48+
Usage: hyp <command> [opts...]
49+
50+
General Commands:
51+
52+
hyp info [urls...] - Show information about one (or more) hypers.
53+
hyp seed {urls...} - Download and make hyper data available to the network.
54+
hyp unseed {urls...} - Stop making hyper data available to the network.
55+
hyp create {drive|bee} - Create a new hyperdrive or hyperbee.
56+
57+
hyp beam {pass_phrase} - Send a stream of data over the network.
58+
59+
Hyperdrive Commands:
60+
61+
hyp drive ls {url} - List the entries of the given hyperdrive URL.
62+
hyp drive mkdir {url} - Create a new directory at the given hyperdrive URL.
63+
hyp drive rmdir {url} - Remove a directory at the given hyperdrive URL.
64+
65+
hyp drive cat {url} - Output the content of the given hyperdrive URL.
66+
hyp drive put {url} [content] - Write a file at the given hyperdrive URL.
67+
hyp drive rm {url} - Remove a file or (if --recursive) a folder at the given hyperdrive URL.
68+
69+
hyp drive diff {source_path_or_url} {target_path_or_url} - Compare two folders in your local filesystem or in hyperdrives. Can optionally "commit" the difference.
70+
hyp drive sync {source_path_or_url} [target_path_or_url] - Continuously sync changes between two folders in your local filesystem or in hyperdrives.
71+
72+
hyp drive http {url} - Host a hyperdrive as using HTTP on the localhost.
73+
74+
Hyperbee Commands:
75+
76+
hyp bee ls {url} - List the entries of the given hyperbee URL.
77+
hyp bee get {url} - Get the value of an entry of the given hyperbee URL.
78+
hyp bee put {url} [value] - Set the value of an entry of the given hyperbee URL.
79+
hyp bee del {url} - Delete an entry of the given hyperbee URL.
80+
81+
Daemon Commands:
82+
83+
hyp daemon status - Check the status of the hyperspace daemon.
84+
hyp daemon start - Start the hyperspace daemon.
85+
hyp daemon stop - Stop the hyperspace and mirroring daemons if active.
86+
87+
Aliases:
88+
89+
hyp sync -> hyp drive sync
90+
hyp diff -> hyp drive diff
91+
hyp ls -> hyp drive ls
92+
hyp cat -> hyp drive cat
93+
hyp put -> hyp drive put
94+
```
95+
96+
## Overview
97+
98+
The [Hypercore Protocol](https://hypercore-protocol.org) is a peer-to-peer network for sharing files and data. This command-line provides a convenient set of tools for accessing the network.
99+
100+
There are two common kinds of "Hypercores":
101+
102+
- **Hyperdrive** A folder containing files.
103+
- **Hyperbee** A key-value database (similar to leveldb).
104+
105+
All data has a URL which starts with `hyper://`. A URL will look like this:
106+
107+
```
108+
hyper://515bbbc1db2139ef27b6c45dfa418c8be6a1dec16823ea7cb9e61af8d060049e/
109+
```
110+
111+
You use these URLs to access the hyper data over the peer-to-peer network. For example:
112+
113+
```
114+
hyp ls hyper://515bbbc1db2139ef27b6c45dfa418c8be6a1dec16823ea7cb9e61af8d060049e/
115+
hyp cat hyper://515bbbc1db2139ef27b6c45dfa418c8be6a1dec16823ea7cb9e61af8d060049e/file.txt
116+
cat diagram.png | hyp put 515bbbc1db2139ef27b6c45dfa418c8be6a1dec16823ea7cb9e61af8d060049e/diagram.png
117+
```
118+
119+
You can create a new hyperdrive or hyperbee using the `create` commands:
120+
121+
```
122+
hyp create drive
123+
```
124+
125+
You can then seed the hyper (or seed a hyper created by somebody else) using the `seed` command:
126+
127+
```
128+
hyp seed hyper://515bbbc1db2139ef27b6c45dfa418c8be6a1dec16823ea7cb9e61af8d060049e/
129+
```
130+
131+
To see what hypers you are currently seeding, run `info`:
132+
133+
```
134+
hyp info
135+
```
136+
137+
## Documentation
138+
139+
The [website documentation](https://hypercore-protocol.org/guides/hyp/) have a lot of useful guides:
140+
141+
- [Full Commands Reference](https://hypercore-protocol.org/guides/hyp/commands/)
142+
- [Guide: Sharing Folders](https://hypercore-protocol.org/guides/hyp/sharing-folders/)
143+
- [Guide: Seeding Data](https://hypercore-protocol.org/guides/hyp/seeding-data/)
144+
- [Guide: Beaming Files](https://hypercore-protocol.org/guides/hyp/beaming-files/)
145+
</details>

bin/hyp.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env node
2+
3+
4+
process.title = "hyp"
5+
6+
import subcommand from 'subcommand'
7+
import fs from 'fs'
8+
import path from 'path'
9+
import { fileURLToPath } from 'url'
10+
11+
import * as hyper from '../lib/hyper/index.js'
12+
13+
import info from '../lib/commands/info.js'
14+
import create from '../lib/commands/create.js'
15+
import seed from '../lib/commands/seed.js'
16+
import unseed from '../lib/commands/unseed.js'
17+
import beam from '../lib/commands/beam.js'
18+
19+
import driveLs from '../lib/commands/drive/ls.js'
20+
import driveCat from '../lib/commands/drive/cat.js'
21+
import driveMkdir from '../lib/commands/drive/mkdir.js'
22+
import driveRmdir from '../lib/commands/drive/rmdir.js'
23+
import drivePut from '../lib/commands/drive/put.js'
24+
import driveRm from '../lib/commands/drive/rm.js'
25+
import driveDiff from '../lib/commands/drive/diff.js'
26+
import driveSync from '../lib/commands/drive/sync.js'
27+
import driveHttp from '../lib/commands/drive/http.js'
28+
29+
import beeLs from '../lib/commands/bee/ls.js'
30+
import beeGet from '../lib/commands/bee/get.js'
31+
import beePut from '../lib/commands/bee/put.js'
32+
import beeDel from '../lib/commands/bee/del.js'
33+
34+
import daemonStatus from '../lib/commands/daemon/status.js'
35+
import daemonStart from '../lib/commands/daemon/start.js'
36+
import daemonStop from '../lib/commands/daemon/stop.js'
37+
38+
import usage from '../lib/usage.js'
39+
40+
// main
41+
// =
42+
43+
const commands = {
44+
info,
45+
seed,
46+
unseed,
47+
create,
48+
beam,
49+
50+
driveLs,
51+
driveCat,
52+
driveMkdir,
53+
driveRmdir,
54+
drivePut,
55+
driveRm,
56+
driveDiff,
57+
driveSync,
58+
driveHttp,
59+
60+
beeLs,
61+
beeGet,
62+
beePut,
63+
beeDel,
64+
65+
daemonStatus,
66+
daemonStart,
67+
daemonStop
68+
}
69+
70+
// handle command aliases
71+
const driveCmdAliases = ['sync', 'diff', 'ls', 'cat', 'put']
72+
var argv = process.argv.slice(2)
73+
if (driveCmdAliases.includes(argv[0])) {
74+
argv.unshift('drive')
75+
}
76+
77+
// match & run the command
78+
var match = subcommand({ commands: Object.values(commands).map(wrapCommand), none })
79+
match(argv)
80+
81+
// error output when no/invalid command is given
82+
function none (args) {
83+
if (args.version) {
84+
const packageJson = JSON.parse(fs.readFileSync(path.join(fileURLToPath(import.meta.url), '../../package.json'), 'utf8'))
85+
console.log(packageJson.version)
86+
process.exit(0)
87+
}
88+
if (args._[0]) {
89+
console.error(`Invalid command: ${args._[0]}`)
90+
} else {
91+
usage(commands)
92+
}
93+
}
94+
95+
function wrapCommand (obj) {
96+
var innerCommand = obj.command
97+
98+
obj.command = async function (...args) {
99+
if (args[0].h || args[0].help) {
100+
usage(commands, null, obj)
101+
process.exit(0)
102+
}
103+
104+
try {
105+
if (!obj.name.startsWith('daemon') && obj.name !== 'beam') {
106+
await hyper.setup()
107+
}
108+
} catch (err) {
109+
console.error('The daemon is not active. Please run:')
110+
console.error('')
111+
console.error(' hyp daemon start')
112+
console.error('')
113+
process.exit(2)
114+
}
115+
116+
try {
117+
await innerCommand(...args)
118+
} catch (err) {
119+
console.error('Error:', err.message)
120+
process.exit(1)
121+
}
122+
}
123+
return obj
124+
}

docs/glossary.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Glossary
2+
3+
A collection of terms used in `hyp` and the [Hypercore Protocol](https://hypercore-protocol.org):
4+
5+
- **Hypercore Protocol**. The network technology behind `hyp`. [See the website](https://hypercore-protocol.org).
6+
- **Hyperdrives**. A peer-to-peer files collection. [See the docs](https://github.com/hypercore-protocol/hyperdrive).
7+
- **Hyperbee**. A peer-to-peer key/value database. [See the docs](https://github.com/mafintosh/hyperbee).
8+
- **Hypercore**. An append-only log upon which Hyperdrives, Hyperbees, and any other hyper structure. [See the docs](https://github.com/hypercore-protocol/hypercore).
9+
- **Hypers** or **Hyper structures**. A short-hand for the various data structures (Hyperdrives, Hyperbees, etc).
10+
- **Hyperspace**. Two meanings:
11+
- A general term for the ecosystem and network of the Hypercore Protocol.
12+
- The name of the daemon program behind `hyp`. [See the docs](https://github.com/hypercore-protocol/hyperspace).
13+
- **Key**. The 64-character hex string that identifies hypers. The key is shared in hyper structure URLs with the `hyper://` scheme.
14+
- **Seeding**. Actively syncing the current data of a hyper-structure and hosting its data from your device for others to access.

docs/guides/beaming-data.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Beaming data
2+
3+
This doc was moved to the website:
4+
5+
https://hypercore-protocol.org/guides/hyp/beaming-files/

docs/guides/creating-a-hyperdrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Creating a hyperdrive
2+
3+
This doc was moved to the website:
4+
5+
https://hypercore-protocol.org/guides/hyp/commands/create/

docs/guides/diffing-a-hyperdrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Diffing hyperdrives and local folders
2+
3+
This doc was moved to the website:
4+
5+
https://hypercore-protocol.org/guides/hyp/commands/drive-diff/

docs/guides/downloading-a-folder.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Downloading a folder from a hyperdrive
2+
3+
This doc was moved to the website:
4+
5+
https://hypercore-protocol.org/guides/hyp/sharing-folders/

0 commit comments

Comments
 (0)