Last active
May 24, 2016 19:17
-
-
Save okdistribute/f4da9530ee2c23216a6438b3f7a9ee5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var test = require('tape') | |
var path = require('path') | |
var fs = require('fs') | |
var raf = require('random-access-file') | |
var hyperdrive = require('hyperdrive') | |
var memdb = require('memdb') | |
test('download with swarm', function (t) { | |
var drive = hyperdrive(memdb()) | |
var drive2 = hyperdrive(memdb()) | |
var archive = drive.createArchive({ | |
file: function (name) { | |
return raf(path.join(__dirname, name)) | |
} | |
}) | |
var ws = archive.createFileWriteStream('hello.txt') // add hello.txt | |
ws.write('hello') | |
ws.write('world') | |
ws.end() | |
archive.finalize(function (err) { // finalize the archive | |
t.error(err, 'no error') | |
var link = archive.key | |
var archive2 = drive2.createArchive(link, { | |
file: function (name) { | |
return raf(path.join(__dirname, name)) | |
} | |
}) | |
archive = drive.createArchive(link, { | |
file: function (name) { | |
return raf(path.join(__dirname, name)) | |
} | |
}) | |
var replication = archive.replicate() | |
var clone = archive2.replicate() | |
replication.pipe(clone).pipe(replication) | |
var stream = archive2.list() | |
stream.on('data', function (entry) { | |
t.same(entry.name, 'hello.txt', 'got entry') | |
archive2.download(entry, function (err) { | |
t.error(err, 'no error') | |
var contents = fs.readFileSync(path.join(__dirname, 'hello.txt')).toString() | |
t.same(contents, 'helloworld', 'contents downloaded to disk') | |
t.end() | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment