-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
40 lines (39 loc) · 1.46 KB
/
test.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
const {DownloadWorker, utils} = require("./index");
// Multi connections
const worker = new DownloadWorker("http://speedtest.tokyo2.linode.com/100MB-tokyo2.bin", "100MB-tokyo2.zip", {
maxConnections: 8
});
worker.on('error', e => {
console.log(e);
})
worker.on('ready', () => {
worker.on('start', () => console.log('started'))
worker.on('progress', (progress) => {
const speed = utils.dynamicSpeedUnitDisplay(progress.bytesPerSecond, 2);
console.log(`${progress.completedPercent}% - ${speed}`)
});
worker.on('finishing', () => console.log('Download is finishing'));
worker.on('end', () => console.log('Download is done'));
worker.start();
});
// setTimeout(() => {
// worker.stop();
// }, 5000);
// setTimeout(() => {
// worker.resume();
// }, 8000);
// Single connection
// const worker = new DownloadWorker("http://speedtest.tokyo2.linode.com/100MB-tokyo2.bin", "100MB.zip", {
// forceSingleConnection: true
// });
// worker.on('ready', () => {
// worker.on('start', () => console.log('started'))
// worker.on('progress', (progress) => {
// const speed = utils.dynamicSpeedUnitDisplay(progress.bytesPerSecond, 2);
// console.log(`${progress.completedPercent}% - ${speed}`)
// });
// worker.on('finishing', () => console.log('Download is finishing'));
// worker.on('end', () => console.log('Download is done'));
// worker.on('error', error => console.log(error));
// worker.start();
// });