Skip to content

Commit

Permalink
chore: test length
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Apr 11, 2024
1 parent 755b2e4 commit 54541cc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/utils/download.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ export const downloadFromURL = async (url: string | RequestOptions): Promise<Buf
await downloadFromURL(res.headers.location!).then(resolve, reject);
}

const expectedLength = res.headers['content-length'];

const data: any[] = [];

res.on('data', (chunk) => data.push(chunk));
res.on('end', () => {
resolve(Buffer.concat(data));
const buffer = Buffer.concat(data);

if(expectedLength && buffer.length.toString() !== expectedLength) {

Check failure on line 20 in src/utils/download.utils.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `·`

Check failure on line 20 in src/utils/download.utils.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected nullable string value in conditional. Please handle the nullish/empty cases explicitly
reject(new Error('Downloaded data size does not match the expected data size.'));
} else {
resolve(buffer);
}
});
res.on('error', reject);
});
Expand Down

0 comments on commit 54541cc

Please sign in to comment.