🔥 Remove debug output from file download

This commit is contained in:
C-3PO 2018-06-21 20:05:57 +02:00
parent c051139c0f
commit 561a40be63
Signed by: c3po
GPG key ID: 62993C4BB4D86F24

View file

@ -13,25 +13,27 @@ export const getFileContents: () => Promise<Buffer> = () => 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();