Skip to content

Commit cd271b3

Browse files
committed
Updates
1 parent dc7aeaf commit cd271b3

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/remoteFile.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ export default class RemoteFile implements GenericFilehandle {
127127
const totalBytes = contentLength ? parseInt(contentLength, 10) : undefined
128128

129129
// Use ReadableStream API for progress reporting if statusCallback is provided
130-
if (statusCallback && res.body) {
130+
if (statusCallback && res.body && totalBytes) {
131131
const reader = res.body.getReader()
132132
const chunks: Uint8Array[] = []
133133
let receivedBytes = 0
134134

135-
// eslint-disable-next-line no-constant-condition
135+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
136136
while (true) {
137137
const { done, value } = await reader.read()
138138

@@ -143,11 +143,9 @@ export default class RemoteFile implements GenericFilehandle {
143143
chunks.push(value)
144144
receivedBytes += value.length
145145

146-
if (statusCallback && totalBytes) {
147-
statusCallback(
148-
`Downloading ${getProgressDisplayStr(receivedBytes, totalBytes)}`,
149-
)
150-
}
146+
statusCallback?.(
147+
`Downloading ${getProgressDisplayStr(receivedBytes, totalBytes)}`,
148+
)
151149
}
152150

153151
// Concatenate chunks
@@ -243,7 +241,6 @@ export default class RemoteFile implements GenericFilehandle {
243241
const chunks: Uint8Array[] = []
244242
let receivedBytes = 0
245243

246-
// eslint-disable-next-line no-constant-condition
247244
while (true) {
248245
const { done, value } = await reader.read()
249246

@@ -259,7 +256,7 @@ export default class RemoteFile implements GenericFilehandle {
259256
)
260257
}
261258

262-
if (encoding === 'utf8') {
259+
if (encoding === 'utf8' || encoding === 'utf-8') {
263260
const decoder = new TextDecoder('utf-8')
264261
return decoder.decode(concatUint8Array(chunks))
265262
} else if (encoding) {
@@ -268,8 +265,7 @@ export default class RemoteFile implements GenericFilehandle {
268265
return concatUint8Array(chunks)
269266
}
270267
} else {
271-
// If no statusCallback, use the simpler approach
272-
if (encoding === 'utf8') {
268+
if (encoding === 'utf8' || encoding === 'utf-8') {
273269
return res.text()
274270
} else if (encoding) {
275271
throw new Error(`unsupported encoding: ${encoding}`)

0 commit comments

Comments
 (0)