aboutsummaryrefslogtreecommitdiffstats
path: root/api.md
blob: 53993a31266b5dfdafabf68c19c4b612875e4bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
## 1.0 Architecture Design

![dat-arch.001.jpg](arch.png)


  * dat: command-line api
  * dat-desk: desktop application
  * dat-server: js api for server daemon
  * hyperdrive: storage layer
  * discovery-swarm: swarm


## dat

Command-line interface for dat

#### `dat link DIR`

Create a new link for the contents of a directory and begin automatically serving the data to a swarm in the background.

  * `--foreground`: run the server in the foreground instead.

#### `dat LINK DIR`

Download a link to a directory and begin automatically serving the data to a swarm in the background.

  * `--foreground`: run the server in the foreground instead.

#### `dat start`

Starts serving dats in the background progress.

  * `--foreground`: run the server in the foreground instead.

#### `dat stop`

Stops serving dats.

#### `dat rm LINK`

Remove a link from the list, stops serving it.

#### `dat ls`

View a static list of the current dat links that are served.

#### `dat mon`

Opens up real-time monitoring panel for viewing progress of running dats. Can provide optional parameter `dat mon LINK` to filter the monitor and logs for a given dat link.


## JS api

A common JavaScript API for Dat.

```
var Dat = require('dat-server')
```

#### `var dat = Dat(opts, cb)`

Options

  * `db`: leveldb instance for underlying hyperdrive
  * `DISCOVERY_SERVER`: the discovery server to use. (default 'discovery1.publicbits.org')
  * `DAT_DOMAIN`: the domain to use (default 'dat.local')

#### `dat.link(dir, cb)`

Create a dat link for the given directory. Does not start sharing the dat. Must use `dat.join` to begin serving the link to the swarm.

```js
var linker = dat.link(dir)
var done = function (err, link) {
  if (err) throw err
  console.log('Done linking!', link)
}
var dir = '/Users/karissa/data/mydata'
var linker = dat.link(dir, done)
linker.on('progress', function (progress) {
  console.log('progress item', progress)
})
```

#### `dat.join(link, cb)`

Join a swarm for the given link. Should be called after `link` or `download`. Throws error if data has not been downloaded or linked.

```js
var done = function (err) {
  if (err) throw err
  console.log('Done downloading!')
}
var link = 'dat://8a82dae10ee8384'
var dir = '/Users/karissa/data/mydata'
var downloader = dat.download(link, dir, done)
downloader.on('progress', function (progress) {
  console.log('progress item', progress)
})
```

#### `dat.leave(link, cb)`

Leave the swarm for the given link.

#### `dat.on('progress', cb)`

Get all progress events from uploading and downloading data.

```js
dat.on('progress', function (progress) {
  console.log(progress)
})
```