Orcus
zip_archive.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6  */
7 
8 #ifndef INCLUDED_ORCUS_ZIP_ARCHIVE_HPP
9 #define INCLUDED_ORCUS_ZIP_ARCHIVE_HPP
10 
11 #include "env.hpp"
12 #include "exception.hpp"
13 
14 #include <string_view>
15 #include <vector>
16 #include <memory>
17 #include <ostream>
18 
19 namespace orcus {
20 
24 struct ORCUS_PSR_DLLPUBLIC zip_file_entry_header
25 {
26  uint32_t header_signature = 0;
27  uint16_t required_version = 0;
28  uint16_t flag = 0;
29  uint16_t compression_method = 0;
30  uint16_t last_modified_time = 0;
31  uint16_t last_modified_date = 0;
32  uint32_t crc32 = 0;
33  uint32_t compressed_size = 0;
34  uint32_t uncompressed_size = 0;
35 
36  std::string filename;
37  std::vector<uint8_t> extra_field;
38 
43 
44  zip_file_entry_header& operator=(const zip_file_entry_header& other);
45  zip_file_entry_header& operator=(zip_file_entry_header&& other);
46 };
47 
48 ORCUS_PSR_DLLPUBLIC std::ostream& operator<<(std::ostream& os, const zip_file_entry_header& header);
49 
50 class zip_archive_stream;
51 
52 class ORCUS_PSR_DLLPUBLIC zip_archive
53 {
54  class impl;
55 
56  std::unique_ptr<impl> mp_impl;
57 
58 public:
59  zip_archive() = delete;
60  zip_archive(const zip_archive&) = delete;
61  zip_archive& operator= (const zip_archive) = delete;
62 
64  ~zip_archive();
65 
71  void load();
72 
80  zip_file_entry_header get_file_entry_header(std::size_t index) const;
81 
89  zip_file_entry_header get_file_entry_header(std::string_view name) const;
90 
98  std::string_view get_file_entry_name(std::size_t index) const;
99 
107  size_t get_file_entry_count() const;
108 
120  std::vector<unsigned char> read_file_entry(std::string_view entry_name) const;
121 };
122 
123 }
124 
125 #endif
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: zip_archive_stream.hpp:19
Definition: zip_archive.hpp:53
std::string_view get_file_entry_name(std::size_t index) const
size_t get_file_entry_count() const
zip_file_entry_header get_file_entry_header(std::string_view name) const
zip_file_entry_header get_file_entry_header(std::size_t index) const
std::vector< unsigned char > read_file_entry(std::string_view entry_name) const
Definition: zip_archive.hpp:25