Skip to content

Commit 297d0f0

Browse files
committed
Updates
1 parent dc7aeaf commit 297d0f0

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default tseslint.config(
5656
'unicorn/prefer-modern-math-apis': 'off',
5757
'unicorn/prefer-node-protocol': 'off',
5858
'unicorn/no-unreadable-array-destructuring': 'off',
59+
'unicorn/text-encoding-identifier-case': 'off',
5960
'unicorn/no-abusive-eslint-disable': 'off',
6061
'unicorn/no-array-callback-reference': 'off',
6162
'unicorn/number-literal-case': 'off',

src/remoteFile.ts

Lines changed: 8 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,7 @@ export default class RemoteFile implements GenericFilehandle {
243241
const chunks: Uint8Array[] = []
244242
let receivedBytes = 0
245243

246-
// eslint-disable-next-line no-constant-condition
244+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
247245
while (true) {
248246
const { done, value } = await reader.read()
249247

@@ -259,7 +257,7 @@ export default class RemoteFile implements GenericFilehandle {
259257
)
260258
}
261259

262-
if (encoding === 'utf8') {
260+
if (encoding === 'utf8' || encoding === 'utf-8') {
263261
const decoder = new TextDecoder('utf-8')
264262
return decoder.decode(concatUint8Array(chunks))
265263
} else if (encoding) {
@@ -268,8 +266,7 @@ export default class RemoteFile implements GenericFilehandle {
268266
return concatUint8Array(chunks)
269267
}
270268
} else {
271-
// If no statusCallback, use the simpler approach
272-
if (encoding === 'utf8') {
269+
if (encoding === 'utf8' || encoding === 'utf-8') {
273270
return res.text()
274271
} else if (encoding) {
275272
throw new Error(`unsupported encoding: ${encoding}`)

0 commit comments

Comments
 (0)