@@ -122,67 +122,15 @@ export default class RemoteFile implements GenericFilehandle {
122122 }
123123
124124 if ( ( res . status === 200 && position === 0 ) || res . status === 206 ) {
125- // Get the total size for progress reporting
126- const contentLength = res . headers . get ( 'content-length' )
127- const totalBytes = contentLength ? parseInt ( contentLength , 10 ) : undefined
128-
129- // Use ReadableStream API for progress reporting if statusCallback is provided
130- if ( statusCallback && res . body ) {
131- const reader = res . body . getReader ( )
132- const chunks : Uint8Array [ ] = [ ]
133- let receivedBytes = 0
134-
135- // eslint-disable-next-line no-constant-condition
136- while ( true ) {
137- const { done, value } = await reader . read ( )
138-
139- if ( done ) {
140- break
141- }
142-
143- chunks . push ( value )
144- receivedBytes += value . length
145-
146- if ( statusCallback && totalBytes ) {
147- statusCallback (
148- `Downloading ${ getProgressDisplayStr ( receivedBytes , totalBytes ) } ` ,
149- )
150- }
151- }
152-
153- // Concatenate chunks
154- const chunksAll = new Uint8Array ( receivedBytes )
155- let position = 0
156- for ( const chunk of chunks ) {
157- chunksAll . set ( chunk , position )
158- position += chunk . length
125+ // try to parse out the size of the remote file
126+ const contentRange = res . headers . get ( 'content-range' )
127+ const sizeMatch = / \/ ( \d + ) $ / . exec ( contentRange || '' )
128+ if ( sizeMatch ?. [ 1 ] ) {
129+ this . _stat = {
130+ size : parseInt ( sizeMatch [ 1 ] , 10 ) ,
159131 }
160-
161- // try to parse out the size of the remote file
162- const contentRange = res . headers . get ( 'content-range' )
163- const sizeMatch = / \/ ( \d + ) $ / . exec ( contentRange || '' )
164- if ( sizeMatch ?. [ 1 ] ) {
165- this . _stat = {
166- size : parseInt ( sizeMatch [ 1 ] , 10 ) ,
167- }
168- }
169-
170- return chunksAll . slice ( 0 , length )
171- } else {
172- // If no statusCallback, use the simpler approach
173- const resData = await res . arrayBuffer ( )
174-
175- // try to parse out the size of the remote file
176- const contentRange = res . headers . get ( 'content-range' )
177- const sizeMatch = / \/ ( \d + ) $ / . exec ( contentRange || '' )
178- if ( sizeMatch ?. [ 1 ] ) {
179- this . _stat = {
180- size : parseInt ( sizeMatch [ 1 ] , 10 ) ,
181- }
182- }
183-
184- return new Uint8Array ( resData . slice ( 0 , length ) )
185132 }
133+ return new Uint8Array ( await res . arrayBuffer ( ) )
186134 }
187135
188136 // eslint-disable-next-line unicorn/prefer-ternary
@@ -243,7 +191,7 @@ export default class RemoteFile implements GenericFilehandle {
243191 const chunks : Uint8Array [ ] = [ ]
244192 let receivedBytes = 0
245193
246- // eslint-disable-next-line no-constant -condition
194+ // eslint-disable-next-line @typescript-eslint/ no-unnecessary -condition
247195 while ( true ) {
248196 const { done, value } = await reader . read ( )
249197
@@ -259,7 +207,7 @@ export default class RemoteFile implements GenericFilehandle {
259207 )
260208 }
261209
262- if ( encoding === 'utf8' ) {
210+ if ( encoding === 'utf8' || encoding === 'utf-8' ) {
263211 const decoder = new TextDecoder ( 'utf-8' )
264212 return decoder . decode ( concatUint8Array ( chunks ) )
265213 } else if ( encoding ) {
@@ -268,8 +216,7 @@ export default class RemoteFile implements GenericFilehandle {
268216 return concatUint8Array ( chunks )
269217 }
270218 } else {
271- // If no statusCallback, use the simpler approach
272- if ( encoding === 'utf8' ) {
219+ if ( encoding === 'utf8' || encoding === 'utf-8' ) {
273220 return res . text ( )
274221 } else if ( encoding ) {
275222 throw new Error ( `unsupported encoding: ${ encoding } ` )
0 commit comments