10#ifndef BITEXTRACTOR_HPP
11#define BITEXTRACTOR_HPP
15#include "bitabstractarchiveopener.hpp"
16#include "biterror.hpp"
17#include "bitexception.hpp"
18#include "bitinputarchive.hpp"
24auto wildcard_match(
const tstring& pattern,
const tstring& str ) -> bool;
33template<
typename Input >
62 inputArchive.extractTo( outDir );
74 inputArchive.
extractTo( outBuffer, index );
86 inputArchive.
extractTo( outStream, index );
113 using namespace filesystem;
115 if ( itemFilter.empty() ) {
116 throw BitException(
"Cannot extract items", make_error_code( BitError::FilterNotSpecified ) );
119 extractMatchingFilter( inArchive, outDir, policy, [ &itemFilter ](
const tstring& itemPath ) ->
bool {
120 return fsutil::wildcard_match( itemFilter, itemPath );
136 using namespace filesystem;
138 if ( itemFilter.empty() ) {
139 throw BitException(
"Cannot extract items", make_error_code( BitError::FilterNotSpecified ) );
142 extractMatchingFilter( inArchive, outBuffer, policy,
143 [ &itemFilter ](
const tstring& itemPath ) ->
bool {
144 return fsutil::wildcard_match( itemFilter, itemPath );
157 const tstring& outDir = {} )
const {
158 if ( indices.empty() ) {
159 throw BitException(
"Cannot extract items", make_error_code( BitError::IndicesNotSpecified ) );
162 BitInputArchive inputArchive( *
this, inArchive );
163 inputArchive.extractTo( outDir, indices );
166#ifdef BIT7Z_REGEX_MATCHING
182 if ( regex.empty() ) {
183 throw BitException(
"Cannot extract items", make_error_code( BitError::FilterNotSpecified ) );
186 const tregex regexFilter( regex, tregex::ECMAScript | tregex::optimize );
187 extractMatchingFilter( inArchive, outDir, policy, [ ®exFilter ](
const tstring& itemPath ) ->
bool {
188 return std::regex_match( itemPath, regexFilter );
206 if ( regex.empty() ) {
207 throw BitException(
"Cannot extract items", make_error_code( BitError::FilterNotSpecified ) );
210 const tregex regexFilter( regex, tregex::ECMAScript | tregex::optimize );
211 return extractMatchingFilter( inArchive, outBuffer, policy,
212 [ ®exFilter ](
const tstring& itemPath ) ->
bool {
213 return std::regex_match( itemPath, regexFilter );
226 void test( Input inArchive )
const {
232 void extractMatchingFilter( Input inArchive,
241 for (
const auto& item : inputArchive ) {
242 const bool itemMatches = filter( item.path() );
243 if ( itemMatches == shouldExtractMatchedItems ) {
249 matchedIndices.push_back( item.index() );
253 if ( matchedIndices.empty() ) {
254 throw BitException(
"Cannot extract items", make_error_code( BitError::NoMatchingItems ) );
257 inputArchive.extractTo( outDir, matchedIndices );
260 void extractMatchingFilter( Input inArchive,
261 vector< byte_t >& outBuffer,
264 BitInputArchive inputArchive( *
this, inArchive );
268 for (
const auto& item : inputArchive ) {
269 const bool itemMatches = filter( item.path() );
270 if ( itemMatches == shouldExtractMatchedItem ) {
273 inputArchive.extractTo( outBuffer, item.index() );
278 throw BitException(
"Failed to extract items", make_error_code( BitError::NoMatchingItems ) );
The Bit7zLibrary class allows accessing the basic functionalities provided by the 7z DLLs.
Definition bit7zlibrary.hpp:56
The BitAbstractArchiveOpener abstract class represents a generic archive opener.
Definition bitabstractarchiveopener.hpp:26
auto format() const noexcept -> const BitInFormat &override
The BitException class represents a generic exception thrown from the bit7z classes.
Definition bitexception.hpp:32
The main namespace of the bit7z library.
Definition bit7zlibrary.hpp:30
FilterPolicy
Enumeration representing the policy according to which the archive handler should treat the items tha...
Definition bitabstractarchivehandler.hpp:66
@ Include
Extract/compress the items that match the pattern.
std::basic_regex< tchar > tregex
Definition bittypes.hpp:98
std::basic_string< tchar > tstring
Definition bittypes.hpp:91