File tree Expand file tree Collapse file tree 3 files changed +23
-10
lines changed
src/main/php/io/archive/zip Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Original file line number Diff line number Diff line change 1+ <?php namespace io \archive \zip ;
2+
3+ use io \streams \OutputStream ;
4+
5+ /** Needs explicit closing */
6+ class RemainsOpen implements OutputStream {
7+ private $ out ;
8+
9+ public function __construct (OutputStream $ out ) { $ this ->out = $ out ; }
10+
11+ public function write ($ bytes ) { $ this ->out ->write ($ bytes ); }
12+
13+ public function flush () { $ this ->out ->flush (); }
14+
15+ public function close ($ force = false ) { $ force && $ this ->out ->close (); }
16+ }
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ class ZipArchiveWriter implements Closeable {
3131 * @param bool $unicode whether to use unicode for entry names
3232 */
3333 public function __construct (OutputStream $ stream , $ unicode = false ) {
34- $ this ->stream = $ stream ;
34+ $ this ->stream = new RemainsOpen ( $ stream) ;
3535 $ this ->unicode = $ unicode ;
3636 }
3737
@@ -261,7 +261,7 @@ public function close() {
261261 strlen ($ comment )
262262 ));
263263 $ this ->stream ->write ($ comment );
264- $ this ->stream ->close ();
264+ $ this ->stream ->close (true );
265265 $ this ->dir = null ;
266266 }
267267
Original file line number Diff line number Diff line change @@ -76,10 +76,6 @@ public function close() {
7676 $ this ->name
7777 );
7878 $ out = $ encryption ->out ($ this ->writer , $ crc32 );
79- while ($ this ->data ->available ()) {
80- $ out ->write ($ this ->data ->read ());
81- }
82- $ out ->close ();
8379 } else {
8480 $ this ->writer ->addEntry (
8581 0 ,
@@ -91,12 +87,13 @@ public function close() {
9187 $ this ->name ,
9288 ''
9389 );
94- while ($ this ->data ->available ()) {
95- $ this ->writer ->stream ->write ($ this ->data ->read ());
96- }
97- // Leave underlying stream open
90+ $ out = $ this ->writer ->stream ;
9891 }
9992
93+ while ($ this ->data ->available ()) {
94+ $ out ->write ($ this ->data ->read ());
95+ }
96+ $ out ->close ();
10097 $ this ->data = null ;
10198 }
10299}
You can’t perform that action at this time.
0 commit comments