CZipSaver.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * CZipSaver.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "COutputStream.h"
  12. #include "MinizipExtensions.h"
  13. class CZipSaver;
  14. class DLL_LINKAGE CZipOutputStream: public COutputStream
  15. {
  16. public:
  17. /**
  18. * @brief constructs zip stream from already opened file
  19. * @param archive archive handle, must be opened
  20. * @param archiveFilename name of file to write
  21. */
  22. explicit CZipOutputStream(CZipSaver * owner_, zipFile archive, const std::string & archiveFilename);
  23. ~CZipOutputStream();
  24. si64 write(const ui8 * data, si64 size) override;
  25. si64 seek(si64 position) override {return -1;};
  26. si64 tell() override {return 0;};
  27. si64 skip(si64 delta) override {return 0;};
  28. si64 getSize() override {return 0;};
  29. private:
  30. zipFile handle;
  31. CZipSaver * owner;
  32. };
  33. class DLL_LINKAGE CZipSaver
  34. {
  35. public:
  36. explicit CZipSaver(std::shared_ptr<CIOApi> api, const boost::filesystem::path & path);
  37. virtual ~CZipSaver();
  38. std::unique_ptr<COutputStream> addFile(const std::string & archiveFilename);
  39. private:
  40. std::shared_ptr<CIOApi> ioApi;
  41. zlib_filefunc64_def zipApi;
  42. zipFile handle;
  43. ///due to minizip design only one file stream may opened at a time
  44. COutputStream * activeStream;
  45. friend class CZipOutputStream;
  46. };