PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » File Formats » File_Archive » Bug #4548

$_File_Archive_Options not global

Details

Submitted2005-06-07 22:54 UTC
Fromtier at gregor-widuch dot de
Assignedvincentlascaux
StatusClosed
PackageFile_Archive
PHP Version4.3.8
OSWindows XP Pro
Roadmaps(Not assigned)

Comments

[2005-06-07 22:54 UTC] tier at gregor-widuch dot de

Description:
------------
In file Archive.php variable $_File_Archive_Options needs to be set global:

global $_File_Archive_Options;
$_File_Archive_Options = array(
'zipCompressionLevel' => 9,
'gzCompressionLevel' => 9,
'tmpDirectory' => '.',
'cache' => null,
'appendRemoveDuplicates' => false
);

[2005-06-08 08:05 UTC] tier at gregor-widuch dot de

$_File_Archive_Options should be set global because some people maybe wants to use File_Archive inside a function or class.

function zipMyData($filename, $exportFilename, $data)
{
require_once "File/Archive.php";
$rd = "";
$zipfile = File_Archive::toArchive($filename, File_Archive::toVariable($rd));
$zipfile->newFile($exportFilename, array());
$zipfile->writeData($renderedData);
$zipfile->close();
return $rd;
}

if $_File_Archive_Options is not set to global the code generates a zip archive but the data is not zipped (I think compressed with level 0). The zipped file is really larger than the original data (but it is not corrupt)

[2005-06-08 11:46 UTC] tier at gregor-widuch dot de

First let me say: it´s a great great class you wrote.

What I reported is maybe not a bug. But it me hours to get it to work. So it would be nice for users to know it.

A last remark:
In your last sample you put the line

require_once "File/Archive.php";

outside the function zipMyData. That is not what I wanted do. If I have the require_once line only in the function no compression is made:

function zipMyData($filename, $exportFilename, $data)
{
require_once "File/Archive.php";
$rd = "";
$zipfile = File_Archive::toArchive($filename, File_Archive::toVariable($rd));
$zipfile->newFile($exportFilename, array());
$zipfile->writeData($data);
$zipfile->close();
return $rd;
}

$data = '';
for($i=0; $i<10000; $i++)
$data .= 'a';

$compressed = zipMyData('test.zip', 'inner.txt', $data);
echo strlen($compressed).'/'.strlen($data)."\n";

Outputs:
10121/10000