File tree 1 file changed +15
-4
lines changed
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -319,16 +319,27 @@ public function addFile($file, $fileinfo = '')
319
319
throw new ArchiveIOException ('Could not open file for reading: ' . $ file );
320
320
}
321
321
while (!feof ($ fp )) {
322
- $ data = fread ( $ fp , 512 );
323
- $ read += strlen ( $ data );
322
+ // try to read 1 MB ( 512 bytes is unperformant)
323
+ $ data = fread ( $ fp , 1048576 );
324
324
if ($ data === false ) {
325
325
break ;
326
326
}
327
327
if ($ data === '' ) {
328
328
break ;
329
329
}
330
- $ packed = pack ("a512 " , $ data );
331
- $ this ->writebytes ($ packed );
330
+ $ dataLen = strlen ($ data );
331
+ $ read += $ dataLen ;
332
+ // how much of data read fully fills 512-byte blocks?
333
+ $ passLen = ($ dataLen >> 9 ) << 9 ;
334
+ if ($ passLen === $ dataLen ) {
335
+ // all - just write the data
336
+ $ this ->writebytes ($ data );
337
+ } else {
338
+ // directly write what fills 512-byte blocks fully
339
+ $ this ->writebytes (substr ($ data , 0 , $ passLen ));
340
+ // pad the reminder to 512 bytes
341
+ $ this ->writebytes (pack ("a512 " , substr ($ data , $ passLen )));
342
+ }
332
343
}
333
344
fclose ($ fp );
334
345
You can’t perform that action at this time.
0 commit comments