diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2022-04-12 15:17:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-12 15:17:13 +0300 |
commit | a3017a437d8730d07252a84d0f42d282ea77031a (patch) | |
tree | 4d313c928245c3ae7fa01b9adccac9012db7e652 /lib | |
parent | d70d90702f242d081bcd5b692bce751ea5073cdf (diff) | |
parent | 95e0723d0cd8eb03975aff5b8c37d75b6d2604b0 (diff) |
Merge pull request #31929 from nextcloud/enh/noid/zip-expose-stat
Expose ZIP stat information
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Archive/ZIP.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/private/Archive/ZIP.php b/lib/private/Archive/ZIP.php index ca9a046ab83..743d313f951 100644 --- a/lib/private/Archive/ZIP.php +++ b/lib/private/Archive/ZIP.php @@ -110,6 +110,9 @@ class ZIP extends Archive { * 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); @@ -124,6 +127,32 @@ class ZIP extends Archive { } /** + * Generator that returns metadata of all files + * + * @return \Generator<array> + */ + public function getAllFilesStat() { + $fileCount = $this->zip->numFiles; + for ($i = 0;$i < $fileCount;$i++) { + 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 */ public function getFiles(): array { |