Improved tar extraction performance by 20%
authorAlexander Ebert <ebert@woltlab.com>
Mon, 20 May 2013 21:47:48 +0000 (23:47 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 20 May 2013 21:47:48 +0000 (23:47 +0200)
wcfsetup/install/files/lib/system/io/Tar.class.php

index 123855907c5bbe0fec23660cc571457b52bdecd7..277b6c701ab2adacc70b2ec9ec4ec0bb4cdd6923 100644 (file)
@@ -64,6 +64,12 @@ class Tar implements IArchive {
         */
        protected $mode = 'rb';
        
+       /**
+        * chunk size for extracting
+        * @var integer
+        */
+       const CHUNK_SIZE = 8192;
+       
        /**
         * Creates a new Tar object.
         * archiveName must be tarball or gzipped tarball
@@ -209,18 +215,11 @@ class Tar implements IArchive {
                
                $targetFile = new File($destination);
                
-               // read data
-               $n = floor($header['size'] / 512);
-               for ($i = 0; $i < $n; $i++) {
-                       $content = $this->file->read(512);
-                       $targetFile->write($content, 512);
-               }
-               if (($header['size'] % 512) != 0) {
-                       $content = $this->file->read(512);
-                       $targetFile->write($content, ($header['size'] % 512));
-               }
-               
+               // read and write data
+               $buffer = $this->file->read($header['size']);
+               $targetFile->write($buffer);
                $targetFile->close();
+               
                if (FileUtil::isApacheModule() || !@$targetFile->is_writable()) {
                        @$targetFile->chmod(0777);
                }