Make Tar::extractToString() much faster
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 8 Jul 2020 10:46:07 +0000 (12:46 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 8 Jul 2020 10:46:07 +0000 (12:46 +0200)
We are building a full in memory string instead of streaming, so let
PHP perform the heavy lifting of building the string in C instead of
doing it manually in 512 Byte chunks.

wcfsetup/install/files/lib/system/io/Tar.class.php

index 2c5f32144820086d5880f1f43083f2334d596581..05357e37401ea04f1cf4d8f7915969ae7ff364be 100644 (file)
@@ -180,15 +180,7 @@ class Tar implements IArchive {
                $this->file->seek($header['offset']);
                
                // read data
-               $content = '';
-               $n = floor($header['size'] / 512);
-               for ($i = 0; $i < $n; $i++) {
-                       $content .= $this->file->read(512);
-               }
-               if (($header['size'] % 512) != 0) {
-                       $buffer = $this->file->read(512);
-                       $content .= substr($buffer, 0, $header['size'] % 512);
-               }
+               $content = $this->file->read($header['size']);
                
                return $content;
        }