🚑 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`;

View file

@ -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);