diff options
author | Karissa McKelvey <karissa@users.noreply.github.com> | 2016-08-29 21:14:32 +0200 |
---|---|---|
committer | Joe Hand <joe@joeahand.com> | 2016-08-29 12:14:32 -0700 |
commit | 17926b349a0ab5a761b0a97dde27f71a1e1f332e (patch) | |
tree | ada2db81418b04e606fec42f909774ca4347e04b /docs/diy-dat.md | |
parent | a253694c308b7b337c7d781c4bbfddefe4bfe53e (diff) | |
download | dat-docs-17926b349a0ab5a761b0a97dde27f71a1e1f332e.tar.gz dat-docs-17926b349a0ab5a761b0a97dde27f71a1e1f332e.zip |
Simplify tree (#19)
* simplify the doc tree
* add faq and cookbook
* add cookbook files
* update build script
* fix contents.json file
* more examples, fix startBytes
* add FAQ
* Examples-> cookbook
* update diy dat with more details and examples
* fix package.json update
* cleanup Dat capitalization + typos, fix #17
* format ecosystem page
* add example dat links and typo fixes
Diffstat (limited to 'docs/diy-dat.md')
-rw-r--r-- | docs/diy-dat.md | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/docs/diy-dat.md b/docs/diy-dat.md deleted file mode 100644 index fb16fc1..0000000 --- a/docs/diy-dat.md +++ /dev/null @@ -1,41 +0,0 @@ -# DIY Dat - -This document shows how to write your own compatible `dat` client using node modules. - -The three essential node modules are called [hyperdrive](https://npmjs.org/hyperdrive), [hyperdrive-archive-swarm](https://npmjs.org/hyperdrive-archive-swarm) and [level](https://npmjs.org/level). Hyperdrive does file synchronization and versioning, hyperdrive-archive-swarm does peer discovery over local networks and the Internet, and level provides a local LevelDB for storing metadata. More details are available in [How Dat Works](how-dat-works.md). The [dat](https://npmjs.org/dat) module itself is just some code that combines these modules and wraps them in a command-line API. - -Here's the minimal code needed to download data from a dat: - -```js -// run this like: node thisfile.js 4c325f7874b4070blahblahetc -// the dat link someone sent us, we want to download the data from it -var link = new Buffer(process.argv[2], 'hex') - -var Hyperdrive = require('hyperdrive') -var Swarm = require('hyperdrive-archive-swarm') -var level = require('level') -var raf = require('random-access-file') -var each = require('stream-each') - -var db = level('./dat.db') -var drive = Hyperdrive(db) -var archive = drive.createArchive(link, { - file: function (name) { - return raf(path.join(self.dir, name)) - } -}) -var swarm = Swarm(archive) - -archive.open(function (err) { - if (err) return console.error(err) - each(archive.list({live: archive.live}), function (data, next) { - var startBytes = self.stats.bytesDown - archive.download(data, function (err) { - if (err) return console.error(err) - console.log('file downloaded', data.relname) - next() - }) - }, done) -}) - -``` |