⚠ Add error message if file too large
This commit is contained in:
parent
d843ce1200
commit
e4c2754493
1 changed files with 7 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
import * as http from 'http';
|
||||
|
||||
const MAX_MEMORY_SIZE = 100 * 1024 * 1024;
|
||||
|
||||
export default function getUrlContents({ host, path }: {host: string, path: string}): Promise<ArrayBuffer> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = http.request({
|
||||
|
@ -11,6 +13,11 @@ export default function getUrlContents({ host, path }: {host: string, path: stri
|
|||
return reject(`Expected status code 200 but received ${response.statusCode}`);
|
||||
}
|
||||
const headerLength = Number(response.headers['content-length']);
|
||||
if (headerLength > MAX_MEMORY_SIZE) {
|
||||
reject('File size too large to be handled in memory.');
|
||||
request.abort();
|
||||
return;
|
||||
}
|
||||
|
||||
const chunkList: Buffer[] = [];
|
||||
let totalLength = 0;
|
||||
|
|
Loading…
Reference in a new issue