Skip to content

Commit 0ce9d27

Browse files
committed
Use yield in contents() instead of returning a single array with all results.
1 parent 10d8901 commit 0ce9d27

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

src/Tar.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,17 @@ public function contents()
9292
throw new ArchiveIOException('Can not read from a closed archive');
9393
}
9494

95-
$result = array();
9695
while ($read = $this->readbytes(512)) {
9796
$header = $this->parseHeader($read);
9897
if (!is_array($header)) {
9998
continue;
10099
}
101100

102101
$this->skipbytes(ceil($header['size'] / 512) * 512);
103-
$result[] = $this->header2fileinfo($header);
102+
yield $this->header2fileinfo($header);
104103
}
105104

106105
$this->close();
107-
return $result;
108106
}
109107

110108
/**

src/Zip.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,16 @@ public function contents()
7777
throw new ArchiveIOException('Can not read from a closed archive');
7878
}
7979

80-
$result = array();
81-
8280
$centd = $this->readCentralDir();
8381

8482
@rewind($this->fh);
8583
@fseek($this->fh, $centd['offset']);
8684

8785
for ($i = 0; $i < $centd['entries']; $i++) {
88-
$result[] = $this->header2fileinfo($this->readCentralFileHeader());
86+
yield $this->header2fileinfo($this->readCentralFileHeader());
8987
}
9088

9189
$this->close();
92-
return $result;
9390
}
9491

9592
/**

0 commit comments

Comments
 (0)