forked from webtorrent/create-torrent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmixed.js
More file actions
72 lines (52 loc) · 2.41 KB
/
mixed.js
File metadata and controls
72 lines (52 loc) · 2.41 KB
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
import fixtures from 'webtorrent-fixtures'
import fs from 'fs'
import parseTorrent from 'parse-torrent'
import path from 'path'
import { sha1 } from 'uint8-util'
import test from 'tape'
import createTorrent from '../index.js'
test('create multi file torrent with array of mixed types', t => {
t.plan(20)
const number11Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '11.txt')
const number10Path = path.join(fixtures.lotsOfNumbers.contentPath, 'big numbers', '10.txt')
const numbersPath = fixtures.numbers.contentPath
const stream = fs.createReadStream(number10Path)
stream.name = '10.txt'
// Note: Order should be preserved
const input = [number11Path, stream, numbersPath]
const startTime = Date.now()
createTorrent(input, {
name: 'multi',
// force piece length to 32KB so info-hash will
// match what transmission generated, since we use
// a different algo for picking piece length
pieceLength: 32768,
private: false // also force `private: false` to match transmission
}, (err, torrent) => {
t.error(err)
const parsedTorrent = parseTorrent(torrent)
t.equals(parsedTorrent.name, 'multi')
t.notOk(parsedTorrent.private)
t.ok(parsedTorrent.created.getTime() >= startTime, 'created time is after start time')
t.ok(Array.isArray(parsedTorrent.announce))
t.deepEquals(path.normalize(parsedTorrent.files[0].path), path.normalize('multi/11.txt'))
t.deepEquals(parsedTorrent.files[0].length, 2)
t.deepEquals(path.normalize(parsedTorrent.files[1].path), path.normalize('multi/10.txt'))
t.deepEquals(parsedTorrent.files[1].length, 2)
t.deepEquals(path.normalize(parsedTorrent.files[2].path), path.normalize('multi/numbers/1.txt'))
t.deepEquals(parsedTorrent.files[2].length, 1)
t.deepEquals(path.normalize(parsedTorrent.files[3].path), path.normalize('multi/numbers/2.txt'))
t.deepEquals(parsedTorrent.files[3].length, 2)
t.deepEquals(path.normalize(parsedTorrent.files[4].path), path.normalize('multi/numbers/3.txt'))
t.deepEquals(parsedTorrent.files[4].length, 3)
t.equal(parsedTorrent.length, 10)
t.equal(parsedTorrent.info.pieces.length, 20)
t.equal(parsedTorrent.pieceLength, 32768)
t.deepEquals(parsedTorrent.pieces, [
'9ad893bb9aeca601a0fab4ba85bd4a4c18b630e3'
])
sha1(parsedTorrent.infoBuffer, hash => {
t.equals(hash, 'bad3f8ea0d1d8a55c18a039dd464f1078f83dba2')
})
})
})