Check for encoded content

This commit is contained in:
Piotr Rogowski 2021-04-06 23:43:21 +02:00
parent ad85f537ac
commit d8a90544d7
No known key found for this signature in database
GPG Key ID: F40F61D5587F5673
1 changed files with 3 additions and 2 deletions

View File

@ -3,9 +3,10 @@ export type onProgress = (percent: number, total: number) => void;
export const fetchWithProgress = async (url: string, onProgress?: onProgress, signal?: AbortSignal): Promise<ArrayBuffer> => {
const response = await fetch(url, { signal });
const contentLength = response.headers.get('Content-Length');
const isContentEncoded = !!response.headers.get('Content-Encoding');
if (!contentLength) {
// fallback
if (!contentLength || isContentEncoded) {
// fallback to full buffer
return response.arrayBuffer();
}