♻️ Extract magic numbers

This commit is contained in:
C-3PO 2018-11-16 03:18:02 +01:00
parent 4440917fc8
commit 0789fa0451
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -1,5 +1,12 @@
import * as childProcess from 'child_process';
/** Minimum download speed of 10 MB/s = 80 MBit/s */
const MINIMUM_SPEED = 10;
/** Maximum download speed of 20 MB/s = 160 MBit/s */
const MAXIMUM_SPEED = 20;
/** Time interval over which the minimum speed is measured to determined whether to timeout. Given in seconds. */
const CHECK_INTERVAL = 15;
/**
* Downloads a file using a curl child process, to allow for speed-limiting and timeout if download is too slow.
* Takes as input the host domain name, the path and the file size
@ -11,9 +18,9 @@ export default function downloadWithCurl({ host, path, tempFileName }: {host: st
const parameters: string[] = [
//...
'--silent',
'--limit-rate', '20m', //maximum speed of 20 MB/s = 160 MBit/s
'--speed-limit', String(Math.round(100 * 1024 * 1024 / 15)), //abort if less than 100 MB in 15 seconds
'--speed-time', '15',
'--limit-rate', `${MAXIMUM_SPEED}m`,
'--speed-limit', String(MINIMUM_SPEED * 1024 * 1024),
'--speed-time', String(CHECK_INTERVAL),
'--output', tempFileName,
url,
];