🔥 Remove debug output from file download
This commit is contained in:
parent
c051139c0f
commit
561a40be63
1 changed files with 7 additions and 5 deletions
|
@ -13,25 +13,27 @@ export const getFileContents: () => Promise<Buffer> = () => new Promise((resolve
|
||||||
host: 'cdn-patch.swtor.com',
|
host: 'cdn-patch.swtor.com',
|
||||||
path,
|
path,
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
console.log(`STATUS: ${response.statusCode}`);
|
if (response.statusCode !== 200) {
|
||||||
console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
|
return reject(`Expected status code 200 but received ${response.statusCode}`);
|
||||||
|
}
|
||||||
|
const headerLength = Number(response.headers['content-length']);
|
||||||
|
|
||||||
const chunkList: Buffer[] = [];
|
const chunkList: Buffer[] = [];
|
||||||
let totalLength = 0;
|
let totalLength = 0;
|
||||||
response.on('data', (chunk: Buffer) => {
|
response.on('data', (chunk: Buffer) => {
|
||||||
console.log(`BODY: ${chunk.length}`);
|
|
||||||
chunkList.push(chunk);
|
chunkList.push(chunk);
|
||||||
totalLength += chunk.length;
|
totalLength += chunk.length;
|
||||||
});
|
});
|
||||||
response.on('end', () => {
|
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);
|
const fileContents = Buffer.concat(chunkList, totalLength);
|
||||||
resolve(fileContents);
|
resolve(fileContents);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
request.on('error', (e) => {
|
request.on('error', (e) => {
|
||||||
console.error(`problem with request: ${e.message}`);
|
|
||||||
reject(e);
|
reject(e);
|
||||||
});
|
});
|
||||||
request.end();
|
request.end();
|
||||||
|
|
Loading…
Reference in a new issue