🚑 Do not throw error if file too large in download module

This commit is contained in:
C-3PO 2018-07-04 22:10:15 +02:00
parent e4d906e48c
commit 34a4372183
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
2 changed files with 4 additions and 9 deletions

View file

@ -1,9 +1,6 @@
import * as fs from 'fs';
import * as http from 'http';
/** Too avoid overloading the server, do not allow large files (> 100 MB) to be handled in memory. */
const MAX_MEMORY_SIZE = 100 * 1024 * 1024;
export default function saveResponse(
resolve: (fileName: fs.ReadStream) => void,
reject: (reason: string) => void,
@ -14,11 +11,8 @@ export default function saveResponse(
return reject(`Expected status code 200 but received ${response.statusCode}.`);
}
//Check file size
//Remember file size
const headerLength = Number(response.headers['content-length']);
if (headerLength > MAX_MEMORY_SIZE) {
return reject(`File size (${headerLength} bytes) too large to be handled in memory.`);
}
const tempFileName = `'/tmp/swtor-patcher-download-${Math.random()}.tmp`;