🚑 Do not throw error if file too large in download module
This commit is contained in:
parent
e4d906e48c
commit
34a4372183
2 changed files with 4 additions and 9 deletions
|
@ -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`;
|
||||
|
||||
|
|
|
@ -15,8 +15,9 @@ export default async function getPatch(product: Product, from: number, to: numbe
|
|||
}
|
||||
|
||||
//start download, making sure that .zip file downloads first
|
||||
const zipFile = getUrlContents(createUrlObject(solidpkg.files[solidpkg.files.length - 1].name));
|
||||
const diskFiles = solidpkg.files.slice(0, solidpkg.files.length - 1).map((file) => downloadUrlContents(createUrlObject(file.name)));
|
||||
const indexOfLastFile = solidpkg.files.length - 1;
|
||||
const zipFile = getUrlContents(createUrlObject(solidpkg.files[indexOfLastFile].name));
|
||||
const diskFiles = solidpkg.files.slice(0, indexOfLastFile).map((file) => downloadUrlContents(createUrlObject(file.name)));
|
||||
|
||||
//we can parse the file entries as soon as the .zip file is loaded
|
||||
const fileEntries = readSsnFile(await zipFile);
|
||||
|
|
Loading…
Reference in a new issue