@@ -34,7 +34,7 @@ class BinaryFileResponse extends Response
34
34
protected $ offset = 0 ;
35
35
protected $ maxlen = -1 ;
36
36
protected $ deleteFileAfterSend = false ;
37
- protected $ chunkSize = 8 * 1024 ;
37
+ protected $ chunkSize = 16 * 1024 ;
38
38
39
39
/**
40
40
* @param \SplFileInfo|string $file The file to stream
@@ -267,7 +267,7 @@ public function prepare(Request $request)
267
267
$ range = $ request ->headers ->get ('Range ' );
268
268
269
269
if (str_starts_with ($ range , 'bytes= ' )) {
270
- [$ start , $ end ] = explode ('- ' , substr ($ range , 6 ), 2 ) + [0 ];
270
+ [$ start , $ end ] = explode ('- ' , substr ($ range , 6 ), 2 ) + [1 => 0 ];
271
271
272
272
$ end = ('' === $ end ) ? $ fileSize - 1 : (int ) $ end ;
273
273
@@ -341,14 +341,15 @@ public function sendContent()
341
341
342
342
$ length = $ this ->maxlen ;
343
343
while ($ length && !feof ($ file )) {
344
- $ read = ( $ length > $ this ->chunkSize ) ? $ this ->chunkSize : $ length ;
345
- $ length -= $ read ;
344
+ $ read = $ length > $ this ->chunkSize || 0 > $ length ? $ this ->chunkSize : $ length ;
345
+ $ read = stream_copy_to_stream ( $ file , $ out , $ read) ;
346
346
347
- stream_copy_to_stream ($ file , $ out , $ read );
348
-
349
- if (connection_aborted ()) {
347
+ if (false === $ read || connection_aborted ()) {
350
348
break ;
351
349
}
350
+ if (0 < $ length ) {
351
+ $ length -= $ read ;
352
+ }
352
353
}
353
354
354
355
fclose ($ out );
0 commit comments