Skip to content

Commit 43e4f35

Browse files
committed
Prevent warning when calling close() multiple times
Fixes #4
1 parent 6690d51 commit 43e4f35

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ ZIP File support for the XP Framework ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
* Fixed issue #4: *Undefined property: [...]ZipFileOutputStream::$data*
7+
when calling `close()` more than once.
8+
(@thekid)
9+
610
## 11.2.0 / 2025-08-16
711

812
* Added compatibility with `xp-framework/math` version 10.0+ - @thekid

src/main/php/io/archive/zip/ZipFileOutputStream.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ public function close() {
8484
0
8585
);
8686
$this->writer->streamWrite($bytes);
87-
unset($this->data);
87+
$this->data= null;
8888
}
8989
}

src/test/php/io/archive/zip/unittest/ZipArchiveWriterTest.class.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace io\archive\zip\unittest;
22

33
use io\archive\zip\{ZipArchiveWriter, ZipDirEntry, ZipFile, ZipFileEntry};
4-
use io\streams\{MemoryInputStream, MemoryOutputStream};
4+
use io\streams\{MemoryInputStream, MemoryOutputStream, StreamTransfer};
55
use lang\IllegalArgumentException;
66
use test\{Assert, Expect, Test};
77

@@ -116,4 +116,19 @@ public function using_unicode_names() {
116116

117117
Assert::equals(['関連事業調査.txt' => 'File contents'], $this->entriesWithContentIn($out, 'secret'));
118118
}
119+
120+
#[Test]
121+
public function transferring_a_file() {
122+
$out= new MemoryOutputStream();
123+
$fixture= new ZipArchiveWriter($out);
124+
$file= $fixture->add(new ZipFileEntry('test.txt'));
125+
126+
$transfer= new StreamTransfer(new MemoryInputStream('File contents'), $file->out());
127+
$transfer->transferAll();
128+
$transfer->close();
129+
130+
$fixture->close();
131+
132+
Assert::equals(['test.txt' => 'File contents'], $this->entriesWithContentIn($out));
133+
}
119134
}

0 commit comments

Comments
 (0)