#pragma once #include #include #include #include #include namespace DB { class ReadBuffer; class ReadBufferFromFileBase; class SeekableReadBuffer; /// Interface for reading an archive. class IArchiveReader : public std::enable_shared_from_this, boost::noncopyable { public: virtual ~IArchiveReader() = default; /// Returns true if there is a specified file in the archive. virtual bool fileExists(const String & filename) = 0; struct FileInfo { UInt64 uncompressed_size; UInt64 compressed_size; Poco::Timestamp last_modified; bool is_encrypted; }; /// Returns the information about a file stored in the archive. virtual FileInfo getFileInfo(const String & filename) = 0; class FileEnumerator { public: virtual ~FileEnumerator() = default; virtual const String & getFileName() const = 0; virtual const FileInfo & getFileInfo() const = 0; virtual bool nextFile() = 0; }; virtual const std::string & getPath() const = 0; /// Starts enumerating files in the archive. virtual std::unique_ptr firstFile() = 0; using NameFilter = std::function; /// Starts reading a file from the archive. The function returns a read buffer, /// you can read that buffer to extract uncompressed data from the archive. /// Several read buffers can be used at the same time in parallel. virtual std::unique_ptr readFile(const String & filename, bool throw_on_not_found) = 0; virtual std::unique_ptr readFile(NameFilter filter, bool throw_on_not_found) = 0; /// It's possible to convert a file enumerator to a read buffer and vice versa. virtual std::unique_ptr readFile(std::unique_ptr enumerator) = 0; virtual std::unique_ptr nextFile(std::unique_ptr read_buffer) = 0; virtual std::unique_ptr currentFile(std::unique_ptr read_buffer) = 0; virtual std::vector getAllFiles() = 0; virtual std::vector getAllFiles(NameFilter filter) = 0; /// Sets password used to decrypt files in the archive. virtual void setPassword(const String & /* password */) {} using ReadArchiveFunction = std::function()>; }; }