aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_compress.php
diff options
context:
space:
mode:
authorDavid M <davidmj@users.sourceforge.net>2006-01-27 04:20:12 +0000
committerDavid M <davidmj@users.sourceforge.net>2006-01-27 04:20:12 +0000
commite77bc7e936d8cec58ca62b4afea09204798597f3 (patch)
tree32f8422983fd0a9a156167ca439dbdb9454c5736 /phpBB/includes/functions_compress.php
parent5922903264ef43d5bfb04af378863945f911018a (diff)
downloadforums-e77bc7e936d8cec58ca62b4afea09204798597f3.tar
forums-e77bc7e936d8cec58ca62b4afea09204798597f3.tar.gz
forums-e77bc7e936d8cec58ca62b4afea09204798597f3.tar.bz2
forums-e77bc7e936d8cec58ca62b4afea09204798597f3.tar.xz
forums-e77bc7e936d8cec58ca62b4afea09204798597f3.zip
- Tar extraction is MUCH faster, we parse the archive ONCE and create the directories on the spot instead of reading it twice and playing magic with file pointers. Also removed a potential leak.
- Zip extraction needs a small shot in the arm, files and archive must be handled a little better. git-svn-id: file:///svn/phpbb/trunk@5497 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_compress.php')
-rw-r--r--phpBB/includes/functions_compress.php111
1 files changed, 35 insertions, 76 deletions
diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php
index 3bc83107f0..c7468d6d30 100644
--- a/phpBB/includes/functions_compress.php
+++ b/phpBB/includes/functions_compress.php
@@ -163,6 +163,7 @@ class compress_zip extends compress
break;
}
+ // TODO: Move the extraction loop inside the signature detection code, small speed boost
switch ($signature)
{
// 'Local File Header'
@@ -196,6 +197,7 @@ class compress_zip extends compress
);
break;
+ // 'Central Directory Header'
case "\x50\x4b\x01\x02":
fread($this->fp, 24);
fread($this->fp, 12 + current(unpack("v", fread($this->fp, 2))) + current(unpack("v", fread($this->fp, 2))) + current(unpack("v", fread($this->fp, 2))));
@@ -244,7 +246,7 @@ class compress_zip extends compress
{
if (!@mkdir("$dst$str", 0777))
{
- trigger_error("Could not create directory $dir");
+ trigger_error("Could not create directory $folder");
}
@chmod("$dst$str", 0777);
}
@@ -433,6 +435,7 @@ class compress_tar extends compress
var $filename = '';
var $mode = '';
var $type = '';
+ var $wrote = false;
function compress_tar($mode, $file, $type = '')
{
@@ -463,97 +466,53 @@ class compress_tar extends compress
$tmp = unpack("Atype", substr($buffer, 156, 1));
$filetype = (int) trim($tmp['type']);
- if ($filetype == 5)
- {
- $mkdir_ary[] = "$dst$filename";
- }
- else if (dirname($filename) != '.')
- {
- $mkdir_alt_ary[] = $dst . dirname($filename);
- }
- }
- }
-
- $mkdir_alt_ary = array_unique($mkdir_alt_ary);
-
- // Create the directory structure
- if (sizeof($mkdir_ary) || sizeof($mkdir_alt_ary))
- {
- if (!sizeof($mkdir_ary) && sizeof($mkdir_alt_ary))
- {
- $mkdir_ary = $mkdir_alt_ary;
- unset($mkdir_alt_ary);
- }
+ $tmp = unpack("A12size", substr($buffer, 124, 12));
+ $filesize = octdec((int) trim($tmp['size']));
- sort($mkdir_ary);
- foreach ($mkdir_ary as $dir)
- {
- $folders = explode('/', $dir);
- foreach ($folders as $folder)
+ if ($filetype == 5)
{
- $str = (!empty($str)) ? $str . '/' . $folder : $folder;
- if(!is_dir($str))
+ if (!is_dir("$dst$filename"))
{
- if (!@mkdir($str, 0777))
+ $str = '';
+ $folders = explode('/', "$dst$filename");
+
+ // Create and folders and subfolders if they do not exist
+ foreach ($folders as $folder)
{
- trigger_error("Could not create directory $folder");
+ $str = (!empty($str)) ? $str . '/' . $folder : $folder;
+ if (!is_dir($str))
+ {
+ if (!@mkdir($str, 0777))
+ {
+ trigger_error("Could not create directory $folder");
+ }
+ @chmod("$str", 0777);
+ }
}
- @chmod("$str", 0777);
}
}
- unset($str);
- }
- }
-
- // If this is a .bz2 we need to close and re-open the file in order
- // to reset the file pointer since we cannot apparently rewind it
- if ($this->isbz)
- {
- $this->close();
- $this->open();
- }
- else
- {
- fseek($this->fp, 0);
- }
-
- // Write out the files
- $size = 0;
- while ($buffer = $fzread($this->fp, 512))
- {
- $tmp = unpack("A6magic", substr($buffer, 257, 6));
-
- if (trim($tmp['magic']) == 'ustar')
- {
- $tmp = unpack("A100name", $buffer);
- $filename = trim($tmp['name']);
-
- $tmp = unpack("Atype", substr($buffer, 156, 1));
- $filetype = (int) trim($tmp['type']);
-
- $tmp = unpack("A12size", substr($buffer, 124, 12));
- $filesize = octdec((int) trim($tmp['size']));
-
- if ($filesize != 0 && ($filetype == 0 || $filetype == "\0"))
+ else if($filesize != 0 && ($filetype == 0 || $filetype == "\0"))
{
+ // Write out the files
if (!($fp = fopen("$dst$filename", 'wb')))
{
trigger_error("Couldn't create file $filename");
}
@chmod("$dst$filename", 0777);
- $size = 0;
- continue;
+ // Grab the file contents
+ $n = floor($filesize / 512);
+ for ($i = 0; $i < $n; $i++)
+ {
+ fwrite($fp, $fzread($this->fp, 512), 512);
+ }
+ if (($filesize % 512) > 0)
+ {
+ fwrite($fp, $fzread($this->fp, 512), ($filesize % 512));
+ }
+ fclose($fp);
}
}
-
- $size += 512;
- $length = ($size > $filesize) ? 512 - ($size - $filesize) : 512;
-
- $tmp = unpack("a512data", $buffer);
-
- fwrite($fp, (string) $tmp['data'], $length);
- unset($buffer);
}
}