17 #ifndef COM_BORA_SOFTWARE__BALAU_UTIL__ZIP 18 #define COM_BORA_SOFTWARE__BALAU_UTIL__ZIP 25 #include <boost/iostreams/categories.hpp> 26 #include <boost/iostreams/concepts.hpp> 27 #include <boost/iostreams/copy.hpp> 28 #include <boost/iostreams/device/file_descriptor.hpp> 29 #include <boost/iostreams/filter/gzip.hpp> 30 #include <boost/iostreams/filtering_stream.hpp> 31 #include <boost/iostreams/filtering_streambuf.hpp> 40 namespace Resource::Impl {
112 template <
typename AllocatorT>
114 return "{ " + Strings::join<AllocatorT>(
134 return "{ " + Strings::join(
163 public:
virtual void open(
const Resource::File & path_,
bool verify);
173 public:
virtual void open(
const Resource::File & path_,
bool verify,
const std::string & pw);
181 return archive !=
nullptr;
202 public: std::string readArchiveComment()
const;
213 public:
long long entryCount()
const;
224 public: std::vector<std::string> entryNames()
const;
235 public:
bool hasEntry(
const std::string & name)
const;
245 public:
long long getEntryIndex(
const std::string & name)
const;
255 public: std::string getEntryName(
long long index)
const;
267 public:
void getEntryInfo(
const std::string & name,
ZipEntryInfo & info)
const;
277 public:
void getEntryInfo(
long long index,
ZipEntryInfo & info)
const;
288 public: std::string readEntryComment(
const std::string & name)
const;
298 public: std::string readEntryComment(
long long index)
const;
310 public: std::vector<char> readEntryAsBytes(
const std::string & name)
const;
320 public: std::vector<char> readEntryAsBytes(
long long index)
const;
332 public: std::string readEntryAsString(
const std::string & name)
const;
342 public: std::string readEntryAsString(
long long index)
const;
353 public:
virtual void close();
362 friend class Resource::Impl::ZipEntrySource;
363 friend class Resource::Impl::ZipEntrySink;
365 private: std::vector<char> readEntryAsBytesImpl(
const ZipEntryInfo & info,
const std::string & name)
const;
366 private: std::string readEntryAsStringImpl(
const ZipEntryInfo & info,
const std::string & name)
const;
369 protected:
enum class EntryType {
370 Directory, File, Either
373 protected:
void openImpl(
const Resource::File & path_,
bool verify,
const std::string & pw,
int mode);
376 protected: std::string cleanUpName(
const std::string & name, EntryType entryType)
const;
378 protected:
long long getEntryIndexClean(
const std::string & cleanName)
const;
379 protected:
void throwZipException(
const std::string & errorMessage)
const;
381 protected:
void * archive;
413 public:
void open(
const Resource::File & path_,
bool verify)
override;
429 public:
void open(
const Resource::File & path_,
bool verify,
const std::string & pw)
override;
438 public:
void putArchiveComment(
const std::string & text);
446 public:
void deleteComment();
457 public:
void putDirectory(
const std::string & name);
467 public:
void putEntry(
const std::string & name,
const Resource::File & bytes);
480 public:
void putEntry(
const std::string & name,
const std::vector<char> & bytes);
493 public:
void putEntry(
const std::string & name,
const std::string & bytes);
505 public:
void renameEntry(
const std::string & name,
const std::string & newName);
516 public:
void deleteEntry(
const std::string & name);
531 public:
void close()
override;
551 public:
void commit();
556 private:
template <
typename SourceFunctionT>
void putEntry(
const std::string & name, SourceFunctionT getSource);
559 private:
void renameDirectory(
const std::string & cleanName,
const std::string & newCleanName);
562 private:
void renameFile(
const std::string & cleanName,
const std::string & newCleanName);
565 private:
void deleteDirectory(
const std::string & cleanName);
568 private:
void deleteFile(
const std::string & cleanName);
575 #endif // COM_BORA_SOFTWARE__BALAU_UTIL__ZIP unsigned short encryptionMethod
The encryption method used.
Definition: Zip.hpp:93
Random access to the entries in a zip archive.
Definition: Zip.hpp:155
std::string name
The name of the entry.
Definition: Zip.hpp:58
bool operator==(const UriComponents &lhs, const UriComponents &rhs)
Returns true if the two URI component instances are equal.
Definition: UriComponents.hpp:335
A file on the local file system.
Information about a zip archive entry (file or directory).
Definition: Zip.hpp:54
std::chrono::system_clock::time_point modificationTime
The last modification time.
Definition: Zip.hpp:78
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
long long index
The entry index within the archive.
Definition: Zip.hpp:63
long long compressedSize
The compressed size of the entry.
Definition: Zip.hpp:73
Transactional modification of entries in a new or existing zip archive.
Definition: Zip.hpp:399
Balau::U8String< AllocatorT > toString(const File &file)
Print the file URI as a UTF-8 string.
Definition: File.hpp:724
A file on the local file system.
Definition: File.hpp:35
unsigned short compressionMethod
The compression method used.
Definition: Zip.hpp:88
Balau exceptions for resources.
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
Resource::File getPath() const
Get the file URI that this unzipper accesses.
Definition: Zip.hpp:189
long long uncompressedSize
The uncompressed size of the entry.
Definition: Zip.hpp:68
unsigned int crc
The CRC of the entry's data.
Definition: Zip.hpp:83
bool isOpen() const
Is an archive currently open?
Definition: Zip.hpp:180