♻️ Extract magic numbers
This commit is contained in:
parent
4440917fc8
commit
0789fa0451
1 changed files with 10 additions and 3 deletions
|
@ -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,
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue