From 561a40be636b343b6ee426f51c7a6d1a35c6bbe3 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Thu, 21 Jun 2018 20:05:57 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20debug=20output=20from?= =?UTF-8?q?=20file=20download?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/getFileContents.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/getFileContents.ts b/src/getFileContents.ts index d8bfc1d..1f64ac2 100644 --- a/src/getFileContents.ts +++ b/src/getFileContents.ts @@ -13,25 +13,27 @@ export const getFileContents: () => Promise = () => new Promise((resolve host: 'cdn-patch.swtor.com', path, }, (response) => { - console.log(`STATUS: ${response.statusCode}`); - console.log(`HEADERS: ${JSON.stringify(response.headers)}`); + if (response.statusCode !== 200) { + return reject(`Expected status code 200 but received ${response.statusCode}`); + } + const headerLength = Number(response.headers['content-length']); const chunkList: Buffer[] = []; let totalLength = 0; response.on('data', (chunk: Buffer) => { - console.log(`BODY: ${chunk.length}`); chunkList.push(chunk); totalLength += chunk.length; }); response.on('end', () => { - console.log('No more data in response.'); + if (totalLength !== headerLength) { + return reject(`Expected length ${headerLength} but received ${totalLength}`); + } const fileContents = Buffer.concat(chunkList, totalLength); resolve(fileContents); }); }); request.on('error', (e) => { - console.error(`problem with request: ${e.message}`); reject(e); }); request.end();