Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ZIP stat information #31929

Merged
merged 3 commits into from
Apr 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/private/Archive/ZIP.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public function mtime(string $path) {
* get the files in a folder
*/
public function getFolder(string $path): array {
// FIXME: multiple calls on getFolder would traverse
// the whole file list over and over again
// maybe use a Generator or cache the list ?
$files = $this->getFiles();
$folderContent = [];
$pathLength = strlen($path);
Expand All @@ -123,6 +126,32 @@ public function getFolder(string $path): array {
return $folderContent;
}

/**
* Generator that returns metadata of all files
*
* @return \Generator<array>
*/
public function getAllFilesStat() {
$fileCount = $this->zip->numFiles;
for ($i = 0;$i < $fileCount;$i++) {
Pytal marked this conversation as resolved.
Show resolved Hide resolved
yield $this->zip->statIndex($i);
}
}

/**
* Return stat information for the given path
*
* @param string path path to get stat information on
* @return ?array stat information or null if not found
*/
public function getStat(string $path): ?array {
$stat = $this->zip->statName($path);
if (!$stat) {
return null;
}
return $stat;
}

/**
* get all files in the archive
*/
Expand Down