💡 Update comments for release path search
This commit is contained in:
parent
07caf282d8
commit
ee3fd0a60f
4 changed files with 21 additions and 9 deletions
35
src/cdn/getUrlContents.ts
Normal file
35
src/cdn/getUrlContents.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
import * as http from 'http';
|
||||
|
||||
export default function getUrlContents({ host, path }: {host: string, path: string}): Promise<ArrayBuffer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = http.request({
|
||||
family: 4,
|
||||
host,
|
||||
path,
|
||||
}, (response) => {
|
||||
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) => {
|
||||
chunkList.push(chunk);
|
||||
totalLength += chunk.length;
|
||||
});
|
||||
response.on('end', () => {
|
||||
if (totalLength !== headerLength) {
|
||||
return reject(`Expected length ${headerLength} but received ${totalLength}`);
|
||||
}
|
||||
const fileContents = Buffer.concat(chunkList, totalLength);
|
||||
resolve(fileContents.buffer as ArrayBuffer);
|
||||
});
|
||||
});
|
||||
|
||||
request.on('error', (e) => {
|
||||
reject(e);
|
||||
});
|
||||
request.end();
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue