cvs: pecl /zip zip_stream.c /zip/examples fopen.php

From: Date: Sun, 12 Mar 2006 14:15:13 +0000
Subject: cvs: pecl /zip zip_stream.c /zip/examples fopen.php
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-5426@lists.php.net to get a copy of this message
pajoye Sun Mar 12 14:15:13 2006 UTC Modified files: /pecl/zip zip_stream.c /pecl/zip/examples fopen.php Log: - enable streams by default uses now the fragment to define the entry: zip:///path/to/my.zip#entryname http://cvs.php.net/viewcvs.cgi/pecl/zip/zip_stream.c?r1=1.3&r2=1.4&diff_format=u Index: pecl/zip/zip_stream.c diff -u pecl/zip/zip_stream.c:1.3 pecl/zip/zip_stream.c:1.4 --- pecl/zip/zip_stream.c:1.3 Tue Jan 17 01:06:57 2006 +++ pecl/zip/zip_stream.c Sun Mar 12 14:15:13 2006 @@ -1,4 +1,4 @@ -/* $Id: zip_stream.c,v 1.3 2006/01/17 01:06:57 pajoye Exp $ */ +/* $Id: zip_stream.c,v 1.4 2006/03/12 14:15:13 pajoye Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -11,6 +11,9 @@ #include "php_streams.h" #include "ext/standard/file.h" #include "fopen_wrappers.h" + +#include "ext/standard/url.h" + struct php_zip_stream_data_t { struct zip *za; struct zip_file *zf; @@ -137,8 +140,6 @@ } /* }}} */ - -#if ZIP_ZIP_USE_WRAPPER /* {{{ php_stream_zip_opener */ php_stream *php_stream_zip_opener(php_stream_wrapper *wrapper, char *path, @@ -156,39 +157,37 @@ struct zip *za; struct zip_file *zf = NULL; + char *fragment; + int fragment_len; int err; php_stream *stream = NULL; struct php_zip_stream_data_t *self; + fragment = strchr(path, '#'); + if (!fragment) { + return NULL; + } if (strncasecmp("zip://", path, 6) == 0) { path += 6; } - path_len = strlen(path); - memcpy(file_dirname, path, path_len); - - file_dirname_len = php_dirname(file_dirname, path_len); - - php_basename(path, path_len, NULL, 0, &file_basename, &file_basename_len TSRMLS_CC); - - - printf("path: %s\n", path); - printf("dirname: %s\n", file_dirname); - printf("basename: %s\n", file_basename); + fragment_len = strlen(fragment); + path_len = strlen(path); + memcpy(file_dirname, path, path_len - fragment_len); + php_basename(path, path_len - fragment_len, NULL, 0, &file_basename, &file_basename_len TSRMLS_CC); + fragment++; if (mode[0] != 'r') { return NULL; } za = zip_open(file_dirname, ZIP_CREATE, &err); if (za) { - printf("Zip %s opened.\n", file_dirname); - zf = zip_fopen(za, file_basename, 0); + zf = zip_fopen(za, fragment, 0); if (zf) { - printf("file opened.\n"); self = emalloc(sizeof(*self)); self->za = za; @@ -233,7 +232,5 @@ NULL, 0 /* is_url */ }; -#endif /* ZIP_USE_WRAPPER */ - #endif /* ZEND_ENGINE_2 */ #endif /* HAVE_ZIP */ http://cvs.php.net/viewcvs.cgi/pecl/zip/examples/fopen.php?r1=1.2&r2=1.3&diff_format=u Index: pecl/zip/examples/fopen.php diff -u pecl/zip/examples/fopen.php:1.2 pecl/zip/examples/fopen.php:1.3 --- pecl/zip/examples/fopen.php:1.2 Sat Mar 11 15:46:58 2006 +++ pecl/zip/examples/fopen.php Sun Mar 12 14:15:13 2006 @@ -4,16 +4,19 @@ } -if (0) { - $fp = fopen('zip://test1.zip/test.txt', 'r'); - while (!feof($fp)) { - $contents .= fread($fp, 2); - echo "$contents\n"; - } - - fclose($fp); - echo "done.\n"; +$fp = fopen('zip://' . dirname(__FILE__) . '/test.zip#test', 'r'); +if (!$fp) { + exit("cannot open\n"); } +while (!feof($fp)) { + $contents .= fread($fp, 2); + echo "$contents\n"; +} + +fclose($fp); +echo "done.\n"; + + $content = ''; $z = new Zip(); $z->open(dirname(__FILE__) . '/test.zip');

« previous php.pecl.cvs (#5426) next »