5656use OCA \Files_Sharing \SharedMount ;
5757use OCP \Constants ;
5858use OCP \Files \Cache \ICacheEntry ;
59+ use OCP \Files \ConnectionLostException ;
5960use OCP \Files \EmptyFileNameException ;
6061use OCP \Files \FileNameTooLongException ;
6162use OCP \Files \InvalidCharacterInPathException ;
@@ -397,10 +398,11 @@ public function readfile($path) {
397398 }
398399 $ handle = $ this ->fopen ($ path , 'rb ' );
399400 if ($ handle ) {
400- $ chunkSize = 524288 ; // 512 kB chunks
401+ $ chunkSize = 524288 ; // 512 kiB chunks
401402 while (!feof ($ handle )) {
402403 echo fread ($ handle , $ chunkSize );
403404 flush ();
405+ $ this ->checkConnectionStatus ();
404406 }
405407 fclose ($ handle );
406408 return $ this ->filesize ($ path );
@@ -423,7 +425,7 @@ public function readfilePart($path, $from, $to) {
423425 }
424426 $ handle = $ this ->fopen ($ path , 'rb ' );
425427 if ($ handle ) {
426- $ chunkSize = 524288 ; // 512 kB chunks
428+ $ chunkSize = 524288 ; // 512 kiB chunks
427429 $ startReading = true ;
428430
429431 if ($ from !== 0 && $ from !== '0 ' && fseek ($ handle , $ from ) !== 0 ) {
@@ -453,6 +455,7 @@ public function readfilePart($path, $from, $to) {
453455 }
454456 echo fread ($ handle , $ len );
455457 flush ();
458+ $ this ->checkConnectionStatus ();
456459 }
457460 return ftell ($ handle ) - $ from ;
458461 }
@@ -462,6 +465,13 @@ public function readfilePart($path, $from, $to) {
462465 return false ;
463466 }
464467
468+ private function checkConnectionStatus (): void {
469+ $ connectionStatus = \connection_status ();
470+ if ($ connectionStatus !== CONNECTION_NORMAL ) {
471+ throw new ConnectionLostException ("Connection lost. Status: $ connectionStatus " );
472+ }
473+ }
474+
465475 /**
466476 * @param string $path
467477 * @return mixed
0 commit comments