From 34a4372183be5b1ffdd619ccc5558089c7c6df2a Mon Sep 17 00:00:00 2001 From: C-3PO Date: Wed, 4 Jul 2018 22:10:15 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=91=20Do=20not=20throw=20error=20if=20?= =?UTF-8?q?file=20too=20large=20in=20download=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cdn/funcs/saveResponse.ts | 8 +------- src/ssn/getPatch.ts | 5 +++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/cdn/funcs/saveResponse.ts b/src/cdn/funcs/saveResponse.ts index 79fed99..9ba09c2 100644 --- a/src/cdn/funcs/saveResponse.ts +++ b/src/cdn/funcs/saveResponse.ts @@ -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`; diff --git a/src/ssn/getPatch.ts b/src/ssn/getPatch.ts index 8bccc96..8050396 100644 --- a/src/ssn/getPatch.ts +++ b/src/ssn/getPatch.ts @@ -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);