cellog Wed Jan 9 07:09:03 2008 UTC
Added files:
/pecl/phar/tests/tartar_gzip.phpt
Modified files:
/pecl/phar TODO package.php phar.c phar_internal.h phar_object.c
tar.c
Log:
implement whole-file compression of phars for phar/tar-based phars
still not 100% working, add failing test
add Phar::isCompressed(), which returns either 0, Phar::GZ, or Phar::BZ2
[DOC]
http://cvs.php.net/viewvc.cgi/pecl/phar/TODO?r1=1.49&r2=1.50&diff_format=u
Index: pecl/phar/TODO
diff -u pecl/phar/TODO:1.49 pecl/phar/TODO:1.50
--- pecl/phar/TODO:1.49 Wed Jan 9 03:53:41 2008
+++ pecl/phar/TODO Wed Jan 9 07:09:03 2008
@@ -68,6 +68,5 @@
X Phar::copy($from, $to); [Greg]
X Phar::delete($what) [Greg]
X Phar::buildFromIterator(Iterator $it[, string $base_directory]) [Greg]
- * Layout: Option to compress all content rather than single files.
- That excludes stub and manifest haeder. (tar only)
+ X Layout: Option to compress all content rather than single files. (tar/phar
only) [Greg]
X clean crap paths like phar://blah.phar/file//../to\\here.php [Greg]
http://cvs.php.net/viewvc.cgi/pecl/phar/package.php?r1=1.29&r2=1.30&diff_format=u
Index: pecl/phar/package.php
diff -u pecl/phar/package.php:1.29 pecl/phar/package.php:1.30
--- pecl/phar/package.php:1.29 Wed Jan 9 03:53:41 2008
+++ pecl/phar/package.php Wed Jan 9 07:09:03 2008
@@ -9,6 +9,7 @@
* include/fopen with include_path all work unmodified within a phar [Greg]
* paths with . and .. work (phar://blah.phar/a/../b.php =>
phar://blah.phar/b.php) [Greg]
* add support for mkdir()/rmdir() and support for empty directories to phar
file format [Greg]
+ * add option to compress the entire phar file for phar/tar file format [Greg]
* implement Phar::copy(string $from, string $to) [Greg]
* implement Phar::buildFromIterator(Iterator $it[, string $base_directory])
[Greg]
* add mapping of include/require from within a phar to location within phar
[Greg]
http://cvs.php.net/viewvc.cgi/pecl/phar/phar.c?r1=1.258&r2=1.259&diff_format=u
Index: pecl/phar/phar.c
diff -u pecl/phar/phar.c:1.258 pecl/phar/phar.c:1.259
--- pecl/phar/phar.c:1.258 Wed Jan 9 03:47:21 2008
+++ pecl/phar/phar.cWed Jan 9 07:09:03 2008
@@ -17,7 +17,7 @@
+--+
*/
-/* $Id: phar.c,v 1.258 2008/01/09 03:47:21 cellog Exp $ */
+/* $Id: phar.c,v 1.259 2008/01/09 07:09:03 cellog Exp $ */
#define PHAR_MAIN 1
#include "phar_internal.h"
@@ -979,7 +979,7 @@
* This is used by phar_open_filename to process the manifest, but can be
called
* directly.
*/
-int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias,
int alias_len, long halt_offset, phar_archive_data** pphar, char **error
TSRMLS_DC) /* {{{ */
+int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias,
int alias_len, long halt_offset, phar_archive_data** pphar, php_uint32
compression, char **error TSRMLS_DC) /* {{{ */
{
char b32[4], *buffer, *endbuffer, *savebuf;
phar_archive_data *mydata = NULL;
@@ -1066,7 +1066,11 @@
PHAR_GET_32(buffer, manifest_flags);
- manifest_flags &= ~PHAR_HDR_COMPRESSION_MASK;
+ manifest_flags &= ~PHAR_HDR_COMPRESSION_MASK;
+
+ manifest_flags &= ~PHAR_FILE_COMPRESSION_MASK;
+ /* remember whether this entire phar was compressed with gz/bzip2 */
+ manifest_flags |= compression;
/* The lowest nibble contains the phar wide flags. The compression
flags can */
/* be ignored on reading because it is being generated anyways. */
@@ -1624,14 +1628,14 @@
{
const char token[] = "__HALT_COMPILER();";
const char zip_magic[] = "PK\x03\x04";
+ const char gz_magic[] = "\x1f\x8b\x08";
+ const char bz_magic[] = "BZh";
char *pos, buffer[1024 + sizeof(token)], test = '\0';
const long readsize = sizeof(buffer) - sizeof(token);
const long tokenlen = sizeof(token) - 1;
long halt_offset;
size_t got;
-
- /* Maybe it's better to compile the file instead of just searching, */
- /* but we only want the offset. So we want a .re scanner to find it. */
+ php_uint32 compression = PHAR_FILE_COMPRESSED_NONE;
if (error) {
*error = NULL;
@@ -1643,6 +1647,9 @@
buffer[sizeof(buffer)-1] = '\0';
memset(buffer, 32, sizeof(token));
halt_offset = 0;
+
+ /* Maybe it's better to compile the file instead of just searching, */
+ /* but we only want the offset. So we want a .re scanner to find it. */
while(!php_stream_eof(fp)) {
if ((got = php_stream_read(fp, buffer+tokenlen, readsize)) <
(size_t) tokenlen) {
MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\"
(truncated entry)")
@@ -1650,19 +1657,85 @@
if (!test) {
test = '\1';