Last active
October 5, 2017 19:06
-
-
Save joehand/b2958b00595f4e8331b50fe265cbe6c7 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 tape = require('tape') | |
var ram = require('random-access-memory') | |
var hyperdrive = require('..') | |
tape('sparse read/write 1, passes', function (t) { | |
var archive = hyperdrive(ram) | |
archive.on('ready', function () { | |
var clone = hyperdrive(ram, archive.key, {sparse: true}) | |
archive.writeFile('/hello.txt', 'world', function (err) { | |
t.error(err, 'no error') | |
archive.writeFile('/hello2.txt', 'world', function (err) { | |
t.error(err, 'no error') | |
var stream = clone.replicate() | |
stream.pipe(archive.replicate()).pipe(stream) | |
clone.metadata.update(checkFiles) | |
}) | |
}) | |
function checkFiles () { | |
clone.stat('/hello.txt', function (err, stat) { | |
t.error(err, 'no error') | |
t.ok(stat, 'has stat') | |
clone.readFile('/hello.txt', function (err, data) { | |
t.error(err, 'no error') | |
t.same(data.toString(), 'world', 'data ok') | |
clone.stat('/hello2.txt', function (err, stat) { | |
t.error(err, 'no error') | |
t.ok(stat, 'has stat') | |
clone.readFile('/hello.txt', function (err, data) { | |
t.error(err, 'no error') | |
t.same(data.toString(), 'world', 'data ok') | |
t.end() | |
}) | |
}) | |
}) | |
}) | |
} | |
}) | |
}) | |
tape('sparse read/write 1, fails', function (t) { | |
var archive = hyperdrive(ram) | |
archive.on('ready', function () { | |
var clone = hyperdrive(ram, archive.key, {sparse: true}) | |
archive.writeFile('/hello.txt', 'world', function (err) { | |
t.error(err, 'no error') | |
archive.writeFile('/hello2.txt', 'world', function (err) { | |
t.error(err, 'no error') | |
var stream = clone.replicate() | |
stream.pipe(archive.replicate()).pipe(stream) | |
clone.metadata.update(start) | |
}) | |
}) | |
function start () { | |
clone.stat('/hello.txt', function (err, stat) { | |
t.error(err, 'no error') | |
t.ok(stat, 'stat ok') | |
clone.readFile('/hello.txt', function (err, data) { | |
t.error(err, 'no error') | |
t.same(data.toString(), 'world', 'data ok') | |
clone.stat('/hello2.txt', function (err, stat) { | |
t.error(err, 'no error') | |
t.ok(stat, 'stat ok') | |
clone.readFile('/hello2.txt', function (err, data) { | |
t.error(err, 'no error') | |
t.same(data.toString(), 'world', 'data ok') | |
t.end() | |
}) | |
}) | |
}) | |
}) | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment