forked from webtorrent/webtorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient-seed.js
95 lines (69 loc) · 2.82 KB
/
client-seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* global Blob */
const fixtures = require('webtorrent-fixtures')
const test = require('tape')
const WebTorrent = require('../index.js')
test('client.seed: torrent file (Buffer)', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
client.on('error', err => { t.fail(err) })
client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.content, {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
}, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
client.remove(torrent, err => { t.error(err, 'torrent removed') })
t.equal(client.torrents.length, 0)
client.destroy(err => { t.error(err, 'client destroyed') })
})
})
test('client.seed: torrent file (Buffer), set name on buffer', t => {
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
client.on('error', err => { t.fail(err) })
client.on('warning', err => { t.fail(err) })
const buf = Buffer.from(fixtures.leaves.content)
buf.name = 'Leaves of Grass by Walt Whitman.epub'
client.seed(buf, { announce: [] }, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
client.remove(torrent, err => { t.error(err, 'torrent removed') })
t.equal(client.torrents.length, 0)
client.destroy(err => { t.error(err, 'client destroyed') })
})
})
test('client.seed: torrent file (Blob)', t => {
if (typeof Blob === 'undefined') return t.end()
t.plan(6)
const client = new WebTorrent({ dht: false, tracker: false, lsd: false })
client.on('error', err => { t.fail(err) })
client.on('warning', err => { t.fail(err) })
client.seed(new Blob([fixtures.leaves.content]), {
name: 'Leaves of Grass by Walt Whitman.epub',
announce: []
}, torrent => {
t.equal(client.torrents.length, 1)
t.equal(torrent.infoHash, fixtures.leaves.parsedTorrent.infoHash)
t.equal(torrent.magnetURI, fixtures.leaves.magnetURI)
client.remove(torrent, err => { t.error(err, 'torrent removed') })
t.equal(client.torrents.length, 0)
client.destroy(err => { t.error(err, 'client destroyed') })
})
})
test('client.seed: duplicate seed)', t => {
t.plan(4)
const client = new WebTorrent()
client.on('error', err => { t.fail(err) })
client.on('warning', err => { t.fail(err) })
client.seed(fixtures.leaves.content, function (torrent1) {
client.seed(fixtures.leaves.content, function (torrent2) {
t.equal(torrent1, torrent2)
t.equal(client.torrents.length, 1)
client.destroy(err => { t.error(err, 'client destroyed') })
t.equal(client.torrents.length, 0)
})
})
})