From dc4d8b5e3ba75256ba952ad5834c77694583ecce Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 20 May 2013 23:47:48 +0200 Subject: [PATCH] Improved tar extraction performance by 20% --- .../install/files/lib/system/io/Tar.class.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/wcfsetup/install/files/lib/system/io/Tar.class.php b/wcfsetup/install/files/lib/system/io/Tar.class.php index 123855907c..277b6c701a 100644 --- a/wcfsetup/install/files/lib/system/io/Tar.class.php +++ b/wcfsetup/install/files/lib/system/io/Tar.class.php @@ -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); } -- 2.20.1