From 310bef1723eb34275a209fa64426994a04fd2d04 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sat, 22 Feb 2025 07:30:16 +0300 Subject: [PATCH] implement ZipFileDevice::list --- src/io/devices/ZipFileDevice.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/io/devices/ZipFileDevice.cpp b/src/io/devices/ZipFileDevice.cpp index cc54af34..eb87844f 100644 --- a/src/io/devices/ZipFileDevice.cpp +++ b/src/io/devices/ZipFileDevice.cpp @@ -1,6 +1,7 @@ #include "ZipFileDevice.hpp" -#include +#include + #include "debug/Logger.hpp" #include "io/memory_istream.hpp" #include "io/deflate_istream.hpp" @@ -217,6 +218,30 @@ uint64_t ZipFileDevice::removeAll(std::string_view path) { return 0; } +class ListPathsGenerator : public PathsGenerator { +public: + ListPathsGenerator(std::vector names) + : names(std::move(names)) {}; + + bool next(path& dst) override { + if (current == names.size()) { + return false; + } + dst = names[current++]; + return true; + } +private: + std::vector names; + size_t current = 0; +}; + std::unique_ptr ZipFileDevice::list(std::string_view path) { - return nullptr; + std::vector names; + auto folder = std::string(path) + "/"; + for (const auto& [name, entry] : entries) { + if (name.find(folder) == 0) { + names.push_back(name); + } + } + return std::make_unique(std::move(names)); }