bit7z 4.0.9
A C++ library for interfacing with the 7-zip shared libs.
Loading...
Searching...
No Matches
BitInputArchive Class Reference

The BitInputArchive class, given a handler object, allows reading/extracting the content of archives. More...

#include <bit7z/bitinputarchive.hpp>

+ Inheritance diagram for BitInputArchive:

Classes

class  ConstIterator
 An iterator for the elements contained in an archive. More...
 

Public Member Functions

 BitInputArchive (const BitAbstractArchiveHandler &handler, const buffer_t &inBuffer, ArchiveStartOffset startOffset=ArchiveStartOffset::None)
 Constructs a BitInputArchive object, opening the archive given in the input buffer.
 
 BitInputArchive (const BitAbstractArchiveHandler &handler, const fs::path &arcPath, ArchiveStartOffset startOffset=ArchiveStartOffset::None)
 Constructs a BitInputArchive object, opening the input file archive.
 
 BitInputArchive (const BitAbstractArchiveHandler &handler, const tstring &inFile, ArchiveStartOffset startOffset=ArchiveStartOffset::None)
 Constructs a BitInputArchive object, opening the input file archive.
 
 BitInputArchive (const BitAbstractArchiveHandler &handler, std::istream &inStream, ArchiveStartOffset startOffset=ArchiveStartOffset::None)
 Constructs a BitInputArchive object, opening the archive by reading the given input stream.
 
auto archivePath () const noexcept -> const tstring &
 
auto archiveProperty (BitProperty property) const -> BitPropVariant
 Gets the specified archive property.
 
auto begin () const noexcept -> BitInputArchive::ConstIterator
 
auto cbegin () const noexcept -> BitInputArchive::ConstIterator
 
auto cend () 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 detectedFormat () const noexcept -> const BitInFormat &
 
auto end () const noexcept -> BitInputArchive::ConstIterator
 
void extractTo (byte_t *buffer, std::size_t size, uint32_t index=0) const
 Extracts a file to the pre-allocated output buffer.
 
template<std::size_t N>
void extractTo (byte_t(&buffer)[N], uint32_t index=0) const
 Extracts a file to the pre-allocated output buffer.
 
void extractTo (const tstring &outDir) const
 Extracts the archive to the chosen directory.
 
void extractTo (const tstring &outDir, const std::vector< uint32_t > &indices) const
 Extracts the specified items to the chosen directory.
 
template<std::size_t N>
void extractTo (std::array< byte_t, N > &buffer, uint32_t index=0) const
 Extracts a file to the pre-allocated output buffer.
 
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 files (inside the archive), and the values are their decompressed contents.
 
void extractTo (std::ostream &outStream, uint32_t index=0) const
 Extracts a file to the output stream.
 
void extractTo (std::vector< byte_t > &outBuffer, uint32_t index=0) const
 Extracts a file to the output buffer.
 
auto find (const tstring &path) const noexcept -> BitInputArchive::ConstIterator
 Find an item in the archive that has the given path.
 
auto handler () const noexcept -> const BitAbstractArchiveHandler &
 
auto isItemEncrypted (uint32_t index) const -> bool
 
auto isItemFolder (uint32_t index) const -> bool
 
auto itemAt (uint32_t index) const -> BitArchiveItemOffset
 Retrieve the item at the given index.
 
auto itemProperty (uint32_t index, BitProperty property) const -> BitPropVariant
 Gets the specified property of an item in the archive.
 
auto itemsCount () const -> uint32_t
 
void test () const
 Tests the archive without extracting its content.
 
void testItem (uint32_t index) const
 Tests the item at the given index inside the archive without extracting it.
 
void useFormatProperty (const wchar_t *name, const BitPropVariant &property) const
 Use the given format property to read the archive.
 
template<typename T , typename = typename std::enable_if< is_explicitly_convertible< T, BitPropVariant >::value >::type>
void useFormatProperty (const wchar_t *name, T &&value) const
 Use the given format property to read the archive.
 

Detailed Description

The BitInputArchive class, given a handler object, allows reading/extracting the content of archives.

Constructor & Destructor Documentation

◆ BitInputArchive() [1/4]

Constructs a BitInputArchive object, opening the input file archive.

Parameters
handlerthe reference to the BitAbstractArchiveHandler object containing all the settings to be used for reading the input archive
inFilethe path to the input archive file
startOffset(optional) specifies whether to search for the archive's start throughout the entire file or only at the beginning. The default behavior is to search at the beginning.

◆ BitInputArchive() [2/4]

BitInputArchive ( const BitAbstractArchiveHandler & handler,
const fs::path & arcPath,
ArchiveStartOffset startOffset = ArchiveStartOffset::None )

Constructs a BitInputArchive object, opening the input file archive.

Parameters
handlerthe reference to the BitAbstractArchiveHandler object containing all the settings to be used for reading the input archive
arcPaththe path to the input archive file
startOffset(optional) whether to search for the archive's start throughout the entire file or only at the beginning. The default behavior is to search at the beginning.

◆ BitInputArchive() [3/4]

BitInputArchive ( const BitAbstractArchiveHandler & handler,
const buffer_t & inBuffer,
ArchiveStartOffset startOffset = ArchiveStartOffset::None )

Constructs a BitInputArchive object, opening the archive given in the input buffer.

Parameters
handlerthe reference to the BitAbstractArchiveHandler object containing all the settings to be used for reading the input archive
inBufferthe buffer containing the input archive
startOffset(optional) whether to search for the archive's start throughout the entire file or only at the beginning. The default behavior is to search at the beginning.

◆ BitInputArchive() [4/4]

Constructs a BitInputArchive object, opening the archive by reading the given input stream.

Parameters
handlerthe reference to the BitAbstractArchiveHandler object containing all the settings to be used for reading the input archive
inStreamthe standard input stream of the input archive
startOffset(optional) whether to search for the archive's start throughout the entire file or only at the beginning. The default behavior is to search at the beginning.

Member Function Documentation

◆ archivePath()

auto archivePath ( ) const -> const tstring &
noexcept
Returns
the path to the archive (the empty string for buffer/stream archives).

◆ archiveProperty()

auto archiveProperty ( BitProperty property) const -> BitPropVariant

Gets the specified archive property.

Parameters
propertythe property to be retrieved.
Returns
the current value of the archive property or an empty BitPropVariant if no value is specified.

◆ begin()

auto begin ( ) const -> BitInputArchive::ConstIterator
noexcept
Returns
an iterator to the first element of the archive; if the archive is empty, the returned iterator will be equal to the end() iterator.

◆ cbegin()

auto cbegin ( ) const -> BitInputArchive::ConstIterator
noexcept
Returns
an iterator to the first element of the archive; if the archive is empty, the returned iterator will be equal to the end() iterator.

◆ cend()

auto cend ( ) const -> BitInputArchive::ConstIterator
noexcept
Returns
an iterator to the element following the last element of the archive; this element acts as a placeholder: attempting to access it results in undefined behavior.

◆ contains()

auto contains ( const tstring & path) const -> bool
noexcept

Find if there is an item in the archive that has the given path.

Parameters
paththe path to be searched in the archive.
Returns
true if and only if an item with the given path exists in the archive.

◆ detectedFormat()

auto detectedFormat ( ) const -> const BitInFormat &
noexcept
Returns
the detected format of the file.

◆ end()

auto end ( ) const -> BitInputArchive::ConstIterator
noexcept
Returns
an iterator to the element following the last element of the archive; this element acts as a placeholder: attempting to access it results in undefined behavior.

◆ extractTo() [1/8]

void extractTo ( byte_t * buffer,
std::size_t size,
uint32_t index = 0 ) const

Extracts a file to the pre-allocated output buffer.

Parameters
bufferthe pre-allocated output buffer.
sizethe size of the output buffer (it must be equal to the unpacked size of the item to be extracted).
indexthe index of the file to be extracted.

◆ extractTo() [2/8]

template<std::size_t N>
void extractTo ( byte_t(&) buffer[N],
uint32_t index = 0 ) const
inline

Extracts a file to the pre-allocated output buffer.

Template Parameters
Nthe size of the output buffer (it must be equal to the unpacked size of the item to be extracted).
Parameters
bufferthe pre-allocated output buffer.
indexthe index of the file to be extracted.

◆ extractTo() [3/8]

void extractTo ( const tstring & outDir) const

Extracts the archive to the chosen directory.

Parameters
outDirthe output directory where the extracted files will be put.

◆ extractTo() [4/8]

void extractTo ( const tstring & outDir,
const std::vector< uint32_t > & indices ) const

Extracts the specified items to the chosen directory.

Parameters
outDirthe output directory where the extracted files will be put.
indicesthe array of indices of the files in the archive that must be extracted.

◆ extractTo() [5/8]

template<std::size_t N>
void extractTo ( std::array< byte_t, N > & buffer,
uint32_t index = 0 ) const
inline

Extracts a file to the pre-allocated output buffer.

Template Parameters
Nthe size of the output buffer (it must be equal to the unpacked size of the item to be extracted).
Parameters
bufferthe pre-allocated output buffer.
indexthe index of the file to be extracted.

◆ extractTo() [6/8]

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 files (inside the archive), and the values are their decompressed contents.

Parameters
outMapthe output map.

◆ extractTo() [7/8]

void extractTo ( std::ostream & outStream,
uint32_t index = 0 ) const

Extracts a file to the output stream.

Parameters
outStreamthe (binary) stream where the content of the archive will be put.
indexthe index of the file to be extracted.

◆ extractTo() [8/8]

void extractTo ( std::vector< byte_t > & outBuffer,
uint32_t index = 0 ) const

Extracts a file to the output buffer.

Parameters
outBufferthe output buffer where the content of the archive will be put.
indexthe index of the file to be extracted.

◆ find()

auto find ( const tstring & path) const -> BitInputArchive::ConstIterator
noexcept

Find an item in the archive that has the given path.

Parameters
paththe path to be searched in the archive.
Returns
an iterator to the item with the given path, or an iterator equal to the end() iterator if no item is found.

◆ handler()

auto handler ( ) const -> const BitAbstractArchiveHandler &
noexcept
Returns
the BitAbstractArchiveHandler object containing the settings for reading the archive.

◆ isItemEncrypted()

auto isItemEncrypted ( uint32_t index) const -> bool
Parameters
indexthe index of an item in the archive.
Returns
true if and only if the item at the given index is encrypted.

◆ isItemFolder()

auto isItemFolder ( uint32_t index) const -> bool
Parameters
indexthe index of an item in the archive.
Returns
true if and only if the item at the given index is a folder.

◆ itemAt()

auto itemAt ( uint32_t index) const -> BitArchiveItemOffset

Retrieve the item at the given index.

Parameters
indexthe index of the item to be retrieved.
Returns
the item at the given index within the archive.

◆ itemProperty()

auto itemProperty ( uint32_t index,
BitProperty property ) const -> BitPropVariant

Gets the specified property of an item in the archive.

Parameters
indexthe index (in the archive) of the item.
propertythe property to be retrieved.
Returns
the current value of the item property or an empty BitPropVariant if the item has no value for the property.

◆ itemsCount()

auto itemsCount ( ) const -> uint32_t
Returns
the number of items contained in the archive.

◆ test()

void test ( ) const

Tests the archive without extracting its content.

If the archive is not valid, a BitException is thrown!

◆ testItem()

void testItem ( uint32_t index) const

Tests the item at the given index inside the archive without extracting it.

If the archive is not valid, or there's no item at the given index, a BitException is thrown!

Parameters
indexthe index of the file to be tested.

◆ useFormatProperty() [1/2]

void useFormatProperty ( const wchar_t * name,
const BitPropVariant & property ) const

Use the given format property to read the archive.

Parameters
namethe name of the property.
propertythe property value.

◆ useFormatProperty() [2/2]

template<typename T , typename = typename std::enable_if< is_explicitly_convertible< T, BitPropVariant >::value >::type>
void useFormatProperty ( const wchar_t * name,
T && value ) const
inline

Use the given format property to read the archive.

Template Parameters
Tthe type of the property.
Parameters
namethe name of the property.
valuethe property value.

The documentation for this class was generated from the following file: