attempting to work out conversion/compression API
| From: | Gregory Beaver | Date: | Thu, 10 Apr 2008 03:53:58 +0000 |
| Subject: | attempting to work out conversion/compression API | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-5359@lists.php.net to get a copy of this message | ||
Hi folks,
How does this look for a conversion/compression API?
We need to allow the conversion of whole archives as well as the
compression of whole archives.
For zip/phar file formats, we need to allow the
compression/decompression of individual files within the archive
To satisfy these three requirements, I'd like to use these methods:
void PharFileInfo->compress(int $compression) // first 4 throw
exceptions on failure like other Phar methods
void PharFileInfo->decompress()
void Phar->compressFiles(int $compression)
void Phar->decompressFiles()
Phar|PharData Phar->convert(int $archivetype[, int $compression =
Phar::NONE][, bool $executable = true][, string $file_extension])
$archivetype could be any of Phar::PHAR, Phar::TAR or Phar::ZIP.
$compression could be any of Phar::NONE, Phar::GZ, or Phar::BZ2
$executable is used to determine whether a Phar or PharData object is
returned. If true, $archivetype must be Phar::TAR or Phar::ZIP
$file_extension can be set to override the automatic renaming
(format/compression-dependent)
convert returns a new object either of Phar or PharData based on the
$executable parameter.
Example code:
<?php
// $phar is "blah.phar" Phar
$phar = new Phar('blah.phar');
// $newphar is "blah.tar.gz" PharData
$newphar = $phar->convert(Phar::TAR, Phar::GZ, false);
// $zipphar is "blah.zip.phar" Phar
$zipphar = $newphar->convert(Phar::ZIP);
// $compphar is "blah.phar.bz2" Phar
$compphar = $phar->convert(Phar::PHAR, Phar::BZ2);
$zipphar->compressFiles(Phar::BZ2); // all internal files compressed
with bzip2
$zipphar->decompressFiles(); // all internal files decompressed
$phar['a.php']->compress(Phar::GZ); // a.php is compressed with gzip
compression inside blah.phar
$phar['a.txt']->decompress(); // a.txt is decompressed.
?>
Greg