Skip to content

Commit 2b1a37e

Browse files
committed
cleanup fetchStream Content-Length handling
We should just get the Content-Length in the first response
1 parent c7f705c commit 2b1a37e

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

Diff for: src/utils/stream.js

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/** @param {Response} response */
2+
const getContentLength = (response) => {
3+
const total = response.headers.get('Content-Length')
4+
if (total) return parseInt(total, 10)
5+
throw new Error('Content-Length not found in response headers')
6+
}
7+
18
/**
29
* @param {string|URL} url
310
* @param {RequestInit} [requestOptions]
@@ -10,18 +17,6 @@ export async function fetchStream(url, requestOptions = {}, options = {}) {
1017
const maxRetries = options.maxRetries || 3
1118
const retryDelay = options.retryDelay || 1000
1219

13-
/** @param {Response} response */
14-
const getContentLength = (response) => {
15-
const total = response.headers.get('Content-Length')
16-
const range = response.headers.get('Content-Range')
17-
if (range) {
18-
const match = range.match(/\/(\d+)$/)
19-
if (match) return parseInt(match[1], 10)
20-
}
21-
if (total) return parseInt(total, 10)
22-
throw new Error('Content-Length not found in response headers')
23-
}
24-
2520
/**
2621
* @param {number} startByte
2722
* @param {AbortSignal} signal

0 commit comments

Comments
 (0)