php-src/ext/phar/tests/files/phar_test.inc

76 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2007-01-21 20:22:36 +00:00
if (function_exists('date_default_timezone_set')) {
date_default_timezone_set('UTC');
}
$manifest = '';
2007-01-21 16:58:23 +00:00
$glags = 0;
foreach($files as $name => $cont)
{
2007-01-21 16:58:23 +00:00
global $gflags, $files;
$comp = NULL;
$crc32= NULL;
$clen = NULL;
$ulen = NULL;
2007-01-21 15:57:12 +00:00
$time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006);
2007-01-21 16:58:23 +00:00
$flags= 0;
2007-01-21 15:57:12 +00:00
$perm = 0x000001B6;
2007-01-21 20:12:50 +00:00
$meta = NULL;
2007-01-21 16:58:23 +00:00
// overwrite if array
2007-01-21 15:57:12 +00:00
if (is_array($cont))
{
2007-01-21 16:58:23 +00:00
foreach(array('comp','crc32','clen','ulen','time','flags','perm','meta','cont') as $what)
2007-01-21 15:57:12 +00:00
{
if (isset($cont[$what]))
{
$$what = $cont[$what];
}
}
}
2007-01-21 16:58:23 +00:00
// create if not yet done
if (empty($comp)) $comp = $cont;
if (empty($ulen)) $ulen = strlen($cont);
if (empty($clen)) $clen = strlen($comp);
if (empty($crc32))$crc32= crc32($cont);
2007-01-21 20:12:50 +00:00
if (isset($meta)) $meta = serialize($meta);
2007-01-21 16:58:23 +00:00
// write manifest entry
$manifest .= pack('V', strlen($name)) . $name;
2007-01-21 20:12:50 +00:00
$manifest .= pack('VVVVVV', $ulen, $time, $clen, $crc32, $flags|$perm, strlen($meta)) . $meta;
2007-01-21 16:58:23 +00:00
// globals
$gflags |= $flags;
$files[$name] = $comp;
}
2007-01-21 16:58:23 +00:00
$alias = 'hio';
if (isset($pmeta)) $pmeta = serialize($pmeta); else $pmeta = '';
$manifest = pack('VnVV', count($files), isset($hasdir) ? 0x1110 : 0x1000, $gflags, strlen($alias)) . $alias . pack('V', strlen($pmeta)) . $pmeta . $manifest;
$file .= pack('V', strlen($manifest)) . $manifest;
2007-01-21 16:58:23 +00:00
foreach($files as $cont)
{
2007-01-21 16:58:23 +00:00
$file .= $cont;
}
file_put_contents($fname, $file);
if (@$gzip) {
$fp = gzopen($fname, 'w');
fwrite($fp, $file);
fclose($fp);
}
if (@$bz2) {
$fp = bzopen($fname, 'w');
fwrite($fp, $file);
fclose($fp);
}
?>