✨ Add file download function
This commit is contained in:
parent
3f5feea1cf
commit
6baaada419
2 changed files with 43 additions and 3 deletions
40
src/getFileContents.ts
Normal file
40
src/getFileContents.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import * as http from 'http';
|
||||||
|
|
||||||
|
export const getFileContents: () => Promise<Buffer> = () => new Promise((resolve, reject) => {
|
||||||
|
const product = 'assets_swtor_de_de';
|
||||||
|
|
||||||
|
//Generate URL
|
||||||
|
const url = `http://cdn-patch.swtor.com/patch/${product}/${product}_-1to0.solidpkg`;
|
||||||
|
const path = `/patch/${product}/${product}_-1to0.solidpkg`;
|
||||||
|
const fileName = url.substr(url.lastIndexOf('/') + 1);
|
||||||
|
|
||||||
|
const request = http.request({
|
||||||
|
family: 4,
|
||||||
|
host: 'cdn-patch.swtor.com',
|
||||||
|
path,
|
||||||
|
}, (response) => {
|
||||||
|
console.log(`STATUS: ${response.statusCode}`);
|
||||||
|
console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
|
||||||
|
|
||||||
|
const chunkList: Buffer[] = [];
|
||||||
|
let totalLength = 0;
|
||||||
|
response.on('data', (chunk) => {
|
||||||
|
console.log(`BODY: ${chunk.length}`);
|
||||||
|
chunkList.push(chunk);
|
||||||
|
totalLength += chunk.length;
|
||||||
|
});
|
||||||
|
response.on('end', () => {
|
||||||
|
console.log('No more data in response.');
|
||||||
|
const fileContents = Buffer.concat(chunkList, totalLength);
|
||||||
|
resolve(fileContents);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
request.on('error', (e) => {
|
||||||
|
console.error(`problem with request: ${e.message}`);
|
||||||
|
reject(e);
|
||||||
|
});
|
||||||
|
request.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
getFileContents();
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"defaultSeverity": "error",
|
"defaultSeverity": "error",
|
||||||
"extends": [
|
"extends": [
|
||||||
"tslint:recommended",
|
"tslint:recommended"
|
||||||
],
|
],
|
||||||
"jsRules": {},
|
"jsRules": {},
|
||||||
"rules": {
|
"rules": {
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
"indent": [true, "spaces", 2],
|
"indent": [true, "spaces", 2],
|
||||||
"max-line-length": false,
|
"max-line-length": false,
|
||||||
"no-bitwise": false,
|
"no-bitwise": false,
|
||||||
"quotemark": [true, "single"],
|
"quotemark": [true, "single"]
|
||||||
},
|
},
|
||||||
"rulesDirectory": [],
|
"rulesDirectory": []
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue