Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support seeding a file from filesystem (path string) #209

Merged
merged 6 commits into from Dec 17, 2014
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

add client.seed tests (buffer, blob, path to file)

  • Loading branch information
feross committed Dec 16, 2014
commit 9e55cc7eec04e07060f32d1695b44f30a7c25187
@@ -8,11 +8,7 @@ var test = require('tape')
var leavesPath = __dirname + '/torrents/leaves.torrent'
var leaves = fs.readFileSync(leavesPath)
var leavesTorrent = parseTorrent(leaves)

function verify (t, client, torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
client.destroy()
}
var leavesBookPath = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'

test('client.add (http url to a torrent file (string))', function (t) {
t.plan(1)
@@ -25,9 +21,10 @@ test('client.add (http url to a torrent file (string))', function (t) {
if (err) throw err
server.listen(port, function () {
var url = 'http://127.0.0.1:' + port
var client1 = new WebTorrent({ dht: false, trackers: false })
client1.add(url, function (torrent) {
verify(t, client1, torrent)
var client = new WebTorrent({ dht: false, trackers: false })
client.add(url, function (torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
client.destroy()
server.close()
})
})
@@ -37,8 +34,19 @@ test('client.add (http url to a torrent file (string))', function (t) {
test('client.add (filesystem path to a torrent file (string))', function (t) {
t.plan(1)

var client1 = new WebTorrent({ dht: false, trackers: false })
client1.add(leavesPath, function (torrent) {
verify(t, client1, torrent)
var client = new WebTorrent({ dht: false, trackers: false })
client.add(leavesPath, function (torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
client.destroy()
})
})

test('client.seed (filesystem path to file (string))', function (t) {
t.plan(1)

var client = new WebTorrent({ dht: false, trackers: false })
client.seed(leavesBookPath, function (torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
client.destroy()
})
})
@@ -5,6 +5,7 @@ var test = require('tape')

var leaves = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesTorrent = parseTorrent(leaves)
var leavesBook = fs.readFileSync(__dirname + '/content/Leaves of Grass by Walt Whitman.epub')

function verify (t, client, torrent) {
t.equal(torrent.infoHash, leavesTorrent.infoHash)
@@ -33,5 +34,28 @@ test('client.add (magnet uri, torrent file, info hash, and parsed torrent)', fun
// parsed torrent (from parse-torrent)
var client5 = new WebTorrent({ dht: false, trackers: false })
verify(t, client5, client5.add(leavesTorrent))
})

test('client.seed (Buffer, Blob)', function (t) {
t.plan(2)

var opts = {
name: 'Leaves of Grass by Walt Whitman.epub'
}

// torrent file (Buffer)
var client1 = new WebTorrent({ dht: false, trackers: false })
client1.seed(leavesBook, opts, function (torrent) {
verify(t, client1, torrent)
})

// Blob
if (typeof Blob !== 'undefined') {
var client2 = new WebTorrent({ dht: false, trackers: false })
client2.seed(new Blob([ leavesBook ]), opts, function (torrent) {
verify(t, client2, torrent)
})
} else {
t.pass('Skipping Blob test because missing `Blob` constructor')
}
})
@@ -7,7 +7,7 @@ var parseTorrent = require('parse-torrent')
var test = require('tape')
var TrackerServer = require('bittorrent-tracker/server')

var leavesFile = __dirname + '/torrents/Leaves of Grass by Walt Whitman.epub'
var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesParsed = parseTorrent(leavesTorrent)

@@ -5,7 +5,7 @@ var portfinder = require('portfinder')
var test = require('tape')
var WebTorrent = require('../')

var leavesFile = __dirname + '/torrents/Leaves of Grass by Walt Whitman.epub'
var leavesFile = __dirname + '/content/Leaves of Grass by Walt Whitman.epub'
var leavesTorrent = fs.readFileSync(__dirname + '/torrents/leaves.torrent')

test('start http server programmatically', function (t) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.