bit7z 4.0.0
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
bitinputarchive.hpp
1/*
2 * bit7z - A C++ static library to interface with the 7-zip shared libraries.
3 * Copyright (c) 2014-2023 Riccardo Ostani - All Rights Reserved.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
8 */
9#ifndef BITINPUTARCHIVE_HPP
10#define BITINPUTARCHIVE_HPP
11
12#include <array>
13#include <map>
14
15#include "bitabstractarchivehandler.hpp"
16#include "bitarchiveitemoffset.hpp"
17#include "bitformat.hpp"
18#include "bitfs.hpp"
19
20struct IInStream;
21struct IInArchive;
22struct IOutArchive;
23
24namespace bit7z {
25
26using std::vector;
27
32 public:
41
49 BitInputArchive( const BitAbstractArchiveHandler& handler, const fs::path& arcPath );
50
59
68
69 BitInputArchive( const BitInputArchive& ) = delete;
70
71 BitInputArchive( BitInputArchive&& ) = delete;
72
73 auto operator=( const BitInputArchive& ) -> BitInputArchive& = delete;
74
75 auto operator=( BitInputArchive&& ) -> BitInputArchive& = delete;
76
77 virtual ~BitInputArchive();
78
82 BIT7Z_NODISCARD auto detectedFormat() const noexcept -> const BitInFormat&;
83
91 BIT7Z_NODISCARD auto archiveProperty( BitProperty property ) const -> BitPropVariant;
92
102 BIT7Z_NODISCARD auto itemProperty( uint32_t index, BitProperty property ) const -> BitPropVariant;
103
107 BIT7Z_NODISCARD auto itemsCount() const -> uint32_t;
108
114 BIT7Z_NODISCARD auto isItemFolder( uint32_t index ) const -> bool;
115
121 BIT7Z_NODISCARD auto isItemEncrypted( uint32_t index ) const -> bool;
122
126 BIT7Z_NODISCARD auto archivePath() const noexcept -> const tstring&;
127
131 BIT7Z_NODISCARD auto handler() const noexcept -> const BitAbstractArchiveHandler&;
132
133 BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
134 inline void extract( const tstring& outDir, const std::vector< uint32_t >& indices = {} ) const {
135 extractTo( outDir, indices );
136 }
137
144 void extractTo( const tstring& outDir, const std::vector< uint32_t >& indices = {} ) const;
145
146 BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
147 inline void extract( std::vector< byte_t >& outBuffer, uint32_t index = 0 ) const {
148 extractTo( outBuffer, index );
149 }
150
157 void extractTo( std::vector< byte_t >& outBuffer, uint32_t index = 0 ) const;
158
159 template< std::size_t N >
160 BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
161 void extract( std::array< byte_t, N >& buffer, uint32_t index = 0 ) const {
162 extractTo( buffer.data(), buffer.size(), index );
163 }
164
173 template< std::size_t N >
174 void extractTo( std::array< byte_t, N >& buffer, uint32_t index = 0 ) const {
175 extractTo( buffer.data(), buffer.size(), index );
176 }
177
178 template< std::size_t N >
179 BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
180 void extract( byte_t (& buffer)[N], uint32_t index = 0 ) const { // NOLINT(*-avoid-c-arrays)
181 extractTo( buffer, N, index );
182 }
183
192 template< std::size_t N >
193 void extractTo( byte_t (& buffer)[N], uint32_t index = 0 ) const { // NOLINT(*-avoid-c-arrays)
194 extractTo( buffer, N, index );
195 }
196
197 BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
198 inline void extract( byte_t* buffer, std::size_t size, uint32_t index = 0 ) const {
199 extractTo( buffer, size, index );
200 }
201
210 void extractTo( byte_t* buffer, std::size_t size, uint32_t index = 0 ) const;
211
212 BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
213 inline void extract( std::ostream& outStream, uint32_t index = 0 ) const {
214 extractTo( outStream, index );
215 }
216
223 void extractTo( std::ostream& outStream, uint32_t index = 0 ) const;
224
225 BIT7Z_DEPRECATED_MSG("Since v4.0; please, use the extractTo method.")
226 inline void extract( std::map< tstring, std::vector< byte_t > >& outMap ) const {
227 extractTo( outMap );
228 }
229
237
243 void test() const;
244
252 void testItem( uint32_t index ) const;
253
254 protected:
255 auto initUpdatableArchive( IOutArchive** newArc ) const -> HRESULT;
256
257 BIT7Z_NODISCARD auto close() const noexcept -> HRESULT;
258
259 friend class BitAbstractArchiveOpener;
260
261 friend class BitAbstractArchiveCreator;
262
263 friend class BitOutputArchive;
264
265 private:
266 IInArchive* mInArchive;
267 const BitInFormat* mDetectedFormat;
268 const BitAbstractArchiveHandler& mArchiveHandler;
269 tstring mArchivePath;
270
271 auto openArchiveStream( const fs::path& name, IInStream* inStream ) -> IInArchive*;
272
273 public:
278 public:
279 // iterator traits
280 using iterator_category BIT7Z_MAYBE_UNUSED = std::input_iterator_tag;
281 using value_type BIT7Z_MAYBE_UNUSED = BitArchiveItemOffset;
282 using reference = const BitArchiveItemOffset&;
283 using pointer = const BitArchiveItemOffset*;
284 using difference_type BIT7Z_MAYBE_UNUSED = uint32_t; //so that count_if returns an uint32_t
285
291 auto operator++() noexcept -> ConstIterator&;
292
298 auto operator++( int ) noexcept -> ConstIterator; // NOLINT(cert-dcl21-cpp)
299
307 auto operator==( const ConstIterator& other ) const noexcept -> bool;
308
316 auto operator!=( const ConstIterator& other ) const noexcept -> bool;
317
323 auto operator*() noexcept -> reference;
324
330 auto operator->() noexcept -> pointer;
331
332 private:
333 BitArchiveItemOffset mItemOffset;
334
335 ConstIterator( uint32_t itemIndex, const BitInputArchive& itemArchive ) noexcept;
336
337 friend class BitInputArchive;
338 };
339
340 using const_iterator BIT7Z_MAYBE_UNUSED BIT7Z_DEPRECATED_MSG("Use ConstIterator") = ConstIterator;
341
346 BIT7Z_NODISCARD auto begin() const noexcept -> BitInputArchive::ConstIterator;
347
352 BIT7Z_NODISCARD auto end() const noexcept -> BitInputArchive::ConstIterator;
353
358 BIT7Z_NODISCARD auto cbegin() const noexcept -> BitInputArchive::ConstIterator;
359
364 BIT7Z_NODISCARD auto cend() const noexcept -> BitInputArchive::ConstIterator;
365
374 BIT7Z_NODISCARD auto find( const tstring& path ) const noexcept -> BitInputArchive::ConstIterator;
375
383 BIT7Z_NODISCARD auto contains( const tstring& path ) const noexcept -> bool;
384
392 BIT7Z_NODISCARD auto itemAt( uint32_t index ) const -> BitArchiveItemOffset;
393};
394
395} // namespace bit7z
396
397#endif //BITINPUTARCHIVE_HPP
Abstract class representing a generic archive creator.
Definition bitabstractarchivecreator.hpp:44
Abstract class representing a generic archive handler.
Definition bitabstractarchivehandler.hpp:74
The BitAbstractArchiveOpener abstract class represents a generic archive opener.
Definition bitabstractarchiveopener.hpp:26
The BitArchiveItemOffset class represents an archived item but doesn't store its properties.
Definition bitarchiveitemoffset.hpp:22
The BitInFormat class specifies an extractable archive format.
Definition bitformat.hpp:58
An iterator for the elements contained in an archive.
Definition bitinputarchive.hpp:277
auto operator++() noexcept -> ConstIterator &
Advances the iterator to the next element in the archive.
The BitInputArchive class, given a handler object, allows reading/extracting the content of archives.
Definition bitinputarchive.hpp:31
BitInputArchive(const BitAbstractArchiveHandler &handler, const std::vector< byte_t > &inBuffer)
Constructs a BitInputArchive object, opening the archive given in the input buffer.
auto end() const noexcept -> BitInputArchive::ConstIterator
void test() const
Tests the archive without extracting its content.
auto archivePath() const noexcept -> const tstring &
auto itemProperty(uint32_t index, BitProperty property) const -> BitPropVariant
Gets the specified property of an item in the archive.
auto find(const tstring &path) const noexcept -> BitInputArchive::ConstIterator
Find an item in the archive that has the given path.
void extractTo(const tstring &outDir, const std::vector< uint32_t > &indices={}) const
Extracts the specified items to the chosen directory.
void extractTo(std::map< tstring, std::vector< byte_t > > &outMap) const
Extracts the content of the archive to a map of memory buffers, where the keys are the paths of the f...
void extractTo(std::vector< byte_t > &outBuffer, uint32_t index=0) const
Extracts a file to the output buffer.
auto isItemEncrypted(uint32_t index) const -> bool
BitInputArchive(const BitAbstractArchiveHandler &handler, const fs::path &arcPath)
Constructs a BitInputArchive object, opening the input file archive.
void testItem(uint32_t index) const
Tests the item at the given index inside the archive without extracting it.
BitInputArchive(const BitAbstractArchiveHandler &handler, const tstring &inFile)
Constructs a BitInputArchive object, opening the input file archive.
auto begin() const noexcept -> BitInputArchive::ConstIterator
auto cbegin() const noexcept -> BitInputArchive::ConstIterator
auto contains(const tstring &path) const noexcept -> bool
Find if there is an item in the archive that has the given path.
auto itemAt(uint32_t index) const -> BitArchiveItemOffset
Retrieve the item at the given index.
void extractTo(byte_t(&buffer)[N], uint32_t index=0) const
Extracts a file to the pre-allocated output buffer.
Definition bitinputarchive.hpp:193
void extractTo(std::ostream &outStream, uint32_t index=0) const
Extracts a file to the output stream.
void extractTo(byte_t *buffer, std::size_t size, uint32_t index=0) const
Extracts a file to the pre-allocated output buffer.
auto detectedFormat() const noexcept -> const BitInFormat &
auto archiveProperty(BitProperty property) const -> BitPropVariant
Gets the specified archive property.
auto handler() const noexcept -> const BitAbstractArchiveHandler &
auto itemsCount() const -> uint32_t
void extractTo(std::array< byte_t, N > &buffer, uint32_t index=0) const
Extracts a file to the pre-allocated output buffer.
Definition bitinputarchive.hpp:174
BitInputArchive(const BitAbstractArchiveHandler &handler, std::istream &inStream)
Constructs a BitInputArchive object, opening the archive by reading the given input stream.
auto cend() const noexcept -> BitInputArchive::ConstIterator
auto isItemFolder(uint32_t index) const -> bool
The BitOutputArchive class, given a creator object, allows creating new archives.
Definition bitoutputarchive.hpp:60
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:30
unsigned char byte_t
A type representing a byte.
Definition bittypes.hpp:36
BitProperty
The BitProperty enum represents the archive/item properties that 7-zip can read or write.
Definition bitpropvariant.hpp:30
The BitPropVariant struct is a light extension to the WinAPI PROPVARIANT struct providing useful gett...
Definition bitpropvariant.hpp:150