Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-10-22 08:49:54 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-10-22 08:49:54 +0400
commitbe5f98e6fb7a153b54b8ba9afeed8d7b60f79646 (patch)
tree650507c14c4269d8ccf8c6e11a723024f7444251 /test
parent2a30d436e9a598dbe202cb1ca5a589f31bc42d9f (diff)
`client.seed` streams into storage
Diffstat (limited to 'test')
-rw-r--r--test/download.js36
1 files changed, 4 insertions, 32 deletions
diff --git a/test/download.js b/test/download.js
index 339d674..9ec7e03 100644
--- a/test/download.js
+++ b/test/download.js
@@ -5,40 +5,12 @@ var DHT = require('bittorrent-dht/client')
var fs = require('fs')
var parseTorrent = require('parse-torrent')
var test = require('tape')
-var TrackerServer = require('bittorrent-tracker').Server
+var TrackerServer = require('bittorrent-tracker/server')
var leavesFile = __dirname + '/torrents/Leaves of Grass by Walt Whitman.epub'
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesParsed = parseTorrent(leavesTorrent)
-var BLOCK_LENGTH = 16 * 1024
-function writeToStorage (storage, file, cb) {
- var pieceIndex = 0
- fs.createReadStream(file)
- .pipe(new BlockStream(leavesParsed.pieceLength, { nopad: true }))
- .on('data', function (piece) {
- var index = pieceIndex
- pieceIndex += 1
-
- var blockIndex = 0
- var s = new BlockStream(BLOCK_LENGTH, { nopad: true })
- s.on('data', function (block) {
- var offset = blockIndex * BLOCK_LENGTH
- blockIndex += 1
-
- storage.writeBlock(index, offset, block)
- })
- s.write(piece)
- s.end()
- })
- .on('end', function () {
- cb(null)
- })
- .on('error', function (err) {
- cb(err)
- })
-}
-
function downloadTrackerTest (t, serverType) {
t.plan(8)
@@ -87,7 +59,7 @@ function downloadTrackerTest (t, serverType) {
t.deepEqual(torrent.files.map(function (file) { return file.name }), names)
- writeToStorage(torrent.storage, leavesFile, function (err) {
+ torrent.storage.load(fs.createReadStream(leavesFile), function (err) {
cb(err, client1)
})
})
@@ -178,7 +150,7 @@ test('Simple download using a tracker (only) via a magnet uri', function (t) {
t.deepEqual(torrent.files.map(function (file) { return file.name }), names)
- writeToStorage(torrent.storage, leavesFile, function (err) {
+ torrent.storage.load(fs.createReadStream(leavesFile), function (err) {
cb(err, client1)
})
})
@@ -264,7 +236,7 @@ test('Simple download using DHT', function (t) {
maybeDone(null)
})
- writeToStorage(torrent.storage, leavesFile, function (err) {
+ torrent.storage.load(fs.createReadStream(leavesFile), function (err) {
wroteStorage = true
maybeDone(err)
})