@@ -77,10 +77,12 @@ protected function initMimeType(): void
7777 /** @noRector */
7878 if (class_exists ('finfo ' )) {
7979 $ finfo = finfo_open (FILEINFO_MIME_TYPE );
80- //We only need the first few bytes to determine the mime-type this helps to reduce RAM-Usage
81- $ this ->mime_type = finfo_buffer ($ finfo , $ this ->file_stream ->read (255 ));
8280 if ($ this ->file_stream ->isSeekable ()) {
81+ //We only need the first few bytes to determine the mime-type this helps to reduce RAM-Usage
82+ $ this ->mime_type = finfo_buffer ($ finfo , $ this ->file_stream ->read (255 ));
8383 $ this ->file_stream ->rewind ();
84+ } else {
85+ $ this ->mime_type = $ this ->getFileTypeFromSuffix ();
8486 }
8587 //All MS-Types are 'application/zip' we need to look at the extension to determine the type.
8688 if ($ this ->mime_type === 'application/zip ' && $ this ->suffix !== 'zip ' ) {
@@ -107,8 +109,17 @@ protected function initSize(): void
107109 $ this ->size += strlen ($ content );
108110 }
109111 }
110-
112+ } catch ( \ Throwable $ exception ) {
111113 if ($ this ->file_stream ->isSeekable ()) {
114+ $ mb_strlen_exists = function_exists ('mb_strlen ' );
115+ //We only read one MB at a time as this radically reduces RAM-Usage
116+ while ($ content = $ this ->file_stream ->read (1_048_576 )) {
117+ if ($ mb_strlen_exists ) {
118+ $ this ->size += mb_strlen ($ content , '8bit ' );
119+ } else {
120+ $ this ->size += strlen ($ content );
121+ }
122+ }
112123 $ this ->file_stream ->rewind ();
113124 }
114125 }
0 commit comments