concanetate rather than substr_replace

git-svn-id: file:///svn/phpbb/trunk@4306 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-07-21 16:10:07 +00:00
parent 852f552b4a
commit cc637e72f0

View file

@ -1,15 +1,24 @@
<? <?
/***************************************************************************
* functions_compress.php
* -------------------
* begin : Saturday, Jul 19, 2003
* copyright : (C) 2001 The phpBB Group
* email : support@phpbb.com
*
* $Id$
*
***************************************************************************/
// Zip creation class from phpMyAdmin 2.3.0 © Tobias Ratschiller, Olivier Müller, Loïc Chapeaux, Marc Delisle /***************************************************************************
// http://www.phpmyadmin.net/ *
// * This program is free software; you can redistribute it and/or modify
// Modified extensively by psoTFX, © phpBB Group, 2003 * it under the terms of the GNU General Public License as published by
// * the Free Software Foundation; either version 2 of the License, or
// Based on work by Eric Mueller and Denis125 * (at your option) any later version.
// Official ZIP file format: http://www.pkware.com/appnote.txt *
***************************************************************************/
// TODO
// Extract files
class compress class compress
{ {
var $fp = 0; var $fp = 0;
@ -84,9 +93,15 @@ class compress
} }
} }
// Zip creation class from phpMyAdmin 2.3.0 © Tobias Ratschiller, Olivier Müller, Loïc Chapeaux, Marc Delisle
// http://www.phpmyadmin.net/
//
// Modified extensively by psoTFX, © phpBB Group, 2003
//
// Based on work by Eric Mueller and Denis125
// Official ZIP file format: http://www.pkware.com/appnote.txt
class compress_zip extends compress class compress_zip extends compress
{ {
var $datasec = array(); var $datasec = array();
var $ctrl_dir = array(); var $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
@ -211,58 +226,54 @@ class compress_tar extends compress
var $fzclose = ''; var $fzclose = '';
var $fzread = ''; var $fzread = '';
var $fzwrite = ''; var $fzwrite = '';
var $fzseek = '';
var $isgz = false; var $isgz = false;
var $isbz = false;
function compress_tar($mode, $file) function compress_tar($mode, $file)
{ {
$this->isgz = (strpos($file, '.tar.gz') !== false || strpos($file, '.tgz') !== false) ? true : false; $this->isgz = (strpos($file, '.tar.gz') !== false || strpos($file, '.tgz') !== false) ? true : false;
$this->isbz = (strpos($file, '.tar.bz2') !== false) ? true : false; $this->isbz = (strpos($file, '.tar.bz2') !== false) ? true : false;
$this->fzopen = ($this->isbz && function_exists('bzopen')) ? 'bzopen' : (($this->isgz && extension_loaded('zlib')) ? 'gzopen' : 'fopen'); $fzopen = ($this->isbz && function_exists('bzopen')) ? 'bzopen' : (($this->isgz && extension_loaded('zlib')) ? 'gzopen' : 'fopen');
$this->fzclose = ($this->isbz && function_exists('bzclose')) ? 'bzclose' : (($this->isgz && extension_loaded('zlib')) ? 'gzclose' : 'fclose');
$this->fzread = ($this->isbz && function_exists('bzread')) ? 'bzread' : (($this->isgz && extension_loaded('zlib')) ? 'gzread' : 'fread');
$this->fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && extension_loaded('zlib')) ? 'gzwrite' : 'fwrite');
$fzopen = $this->fzopen;
return $this->fp = @$fzopen($phpbb_root_path . $file, $mode . 'b'); return $this->fp = @$fzopen($phpbb_root_path . $file, $mode . 'b');
} }
function extract($dst) function extract($dst)
{ {
$fzread = ($this->isbz && function_exists('bzread')) ? 'bzread' : (($this->isgz && extension_loaded('zlib')) ? 'gzread' : 'fread');
} }
function close() function close()
{ {
$fzclose = $this->fzclose; $fzclose = ($this->isbz && function_exists('bzclose')) ? 'bzclose' : (($this->isgz && extension_loaded('zlib')) ? 'gzclose' : 'fclose');
$fzclose($this->fp); $fzclose($this->fp);
} }
function data($name, $data, $mtime = false, $is_dir = false) function data($name, $data, $mtime = false, $is_dir = false)
{ {
$fzwrite = $this->fzwrite; $fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && extension_loaded('zlib')) ? 'gzwrite' : 'fwrite');
$fzread = $this->fzread;
$mode = ($is_dir) ? '493' : '436'; $mode = ($is_dir) ? '493' : '436';
$mtime = (!$mtime) ? time() : $mtime; $mtime = (!$mtime) ? time() : $mtime;
$filesize = ($is_dir) ? 0 : strlen($data); $filesize = ($is_dir) ? 0 : strlen($data);
$typeflag = ($is_dir) ? '5' : ''; $typeflag = ($is_dir) ? '5' : '';
$header = pack("x512", 0); $header = '';
$header = substr_replace($header, pack("a100", $name), 0, 100); $header .= pack("a100", $name);
$header = substr_replace($header, pack("a8", sprintf("%07o", $mode)), 100, 8); $header .= pack("a8", sprintf("%07o", $mode));
// $header = substr_replace($header, pack("a8", sprintf("%07o", 0)), 108, 8); $header .= pack("a8", sprintf("%07o", 0));
// $header = substr_replace($header, pack("a8", sprintf("%07o", 0)), 116, 8); $header .= pack("a8", sprintf("%07o", 0));
$header = substr_replace($header, pack("a12", sprintf("%011o", $filesize)), 124, 12); $header .= pack("a12", sprintf("%011o", $filesize));
$header = substr_replace($header, pack("a12", sprintf("%011o", $mtime)), 136, 12); $header .= pack("a12", sprintf("%011o", $mtime));
$header = substr_replace($header, pack("a", $typeflag), 156, 1); $header .= ' ';
$header .= pack("a", $typeflag);
$header = substr_replace($header, 'ustar', 257, 5); $header .= pack("a100", '');
$header = substr_replace($header, '00', 263, 2); $header .= 'ustar';
$header .= pack("x");
// Space padded for checksum $header .= '00';
$header = substr_replace($header, ' ', 148, 8); $header .= pack("x247");
// Checksum
for ($i = 0; $i < 512; $i++) for ($i = 0; $i < 512; $i++)
{ {
$b = unpack("c1char", substr($header, $i, 1)); $b = unpack("c1char", substr($header, $i, 1));