SpectMorph
smzip.hh
1 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl-2.1.html
2 
3 #ifndef SPECTMORPH_ZIP_HH
4 #define SPECTMORPH_ZIP_HH
5 
6 #include <string>
7 #include <vector>
8 
9 #include "smutils.hh"
10 
11 namespace SpectMorph
12 {
13 
14 class ZipReader
15 {
16  void *reader = nullptr;
17  bool need_close = false;
18  int32_t m_error = 0;
19  void *read_mem_stream = nullptr;
20  std::vector<uint8_t> m_data;
21 public:
22  ZipReader (const std::string& filename);
23  ZipReader (const std::vector<uint8_t>& data);
24  ~ZipReader();
25 
26  std::vector<std::string> filenames();
27  Error error() const;
28  std::vector<uint8_t> read (const std::string& name);
29 
30  static bool is_zip (const std::string& name);
31 };
32 
33 class ZipWriter
34 {
35  void *writer = nullptr;
36  bool need_close = false;
37  int32_t m_error = 0;
38  void *write_mem_stream = nullptr;
39 public:
40  enum class Compress { STORE = 0, DEFLATE };
41 
42  ZipWriter (const std::string& filename);
43  ZipWriter();
44  ~ZipWriter();
45  void add (const std::string& filename, const std::vector<uint8_t>& data, Compress compress = Compress::DEFLATE);
46  void add (const std::string& filename, const std::string& text, Compress compress = Compress::DEFLATE);
47  void close();
48  Error error() const;
49 
50  std::vector<uint8_t> data();
51 };
52 
53 }
54 
55 #endif
Definition: smutils.hh:102
Definition: smzip.hh:15
Definition: smzip.hh:34