-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.js
54 lines (41 loc) · 1.27 KB
/
example.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
var fs = require('fs');
var Torrent = require('./index');
//Some sort of readable stream which is one file to be turned into a torrent
var rs = fs.createReadStream('./README.md');
//Some sort of writeable stream to which a torrent file will be written
var ws = fs.createWriteStream('./test' + Date.now() + '.torrent');
//The torrent streamer
var ts = new Torrent({
announce: "http://totally_a_real_tracker.com/announce",
name: "ReadMe",
pieceLength: 65536, //64k = 65536, 256k = 262144, 512k = 524288 (defaults to 256k)
createdBy: "Rob Riddle"
});
rs.pipe(ts);
ts.pipe(ws);
/**
* Mutli-file example
*/
var rs1 = fs.createReadStream('./README.md');
var rs2 = fs.createReadStream('./license.md');
var nws = fs.createWriteStream('./multi' + Date.now() + '.torrent');
var mts = new Torrent({
announce: "http://totally_a_real_tracker.com/announce",
name: "MyDirectory",
encoding: 'UTF-8',
pieceLength: 2097152
});
mts.addFile(rs1, 'readme.md');
mts.addFile(rs2, 'license.md');
mts.pipe(nws);
/**
* Multi-tracker example
*/
var rs3 = fs.createReadStream('./README.md');
var tws = fs.createWriteStream('./tracker' + Date.now() + '.torrent');
var ts2 = new Torrent({
name: "ReadMe",
trackers: [["tracker1", "tracker2"], ["backup1"]]
});
rs3.pipe(ts2);
ts2.pipe(tws);