Skip to content

BitArchiveReader

Oz edited this page Jan 20, 2023 · 8 revisions

The BitArchiveReader class allows reading metadata of archives, as well as extracting them.

#include <bit7z/bitarchivereader.hpp>

inherits from BitAbstractArchiveOpener, BitInputArchive.

List of all members

Public Members

Return type Name
BitArchiveReader( const Bit7zLibrary& lib, const tstring& in_archive, const BitInFormat& format = BitFormat::Auto, const tstring& password = {} )
BitArchiveReader( const Bit7zLibrary& lib, const std::vector< byte_t >& in_archive, const BitInFormat& format = BitFormat::Auto, const tstring& password = {} )
BitArchiveReader( const Bit7zLibrary& lib, std::istream& in_archive, const BitInFormat& format = BitFormat::Auto, const tstring& password = {} )
~BitArchiveReader() override = default
map< BitProperty, BitPropVariant > archiveProperties() const
vector< BitArchiveItemInfo > items() const
uint32_t foldersCount() const
uint32_t filesCount() const
uint64_t size() const
uint64_t packSize() const
bool hasEncryptedItems() const
uint32_t volumesCount() const
bool isMultiVolume() const
bool isSolid() const
const BitInFormat & format() const noexcept override
const BitInFormat & extractionFormat() const noexcept
const Bit7zLibrary & library() const noexcept
tstring password() const
bool retainDirectories() const noexcept
bool isPasswordDefined() const noexcept
TotalCallback totalCallback() const
ProgressCallback progressCallback() const
RatioCallback ratioCallback() const
FileCallback fileCallback() const
PasswordCallback passwordCallback() const
OverwriteMode overwriteMode() const
void setPassword( const tstring& password )
void clearPassword() noexcept
void setRetainDirectories( bool retain ) noexcept
void setTotalCallback( const TotalCallback& callback )
void setProgressCallback( const ProgressCallback& callback )
void setRatioCallback( const RatioCallback& callback )
void setFileCallback( const FileCallback& callback )
void setPasswordCallback( const PasswordCallback& callback )
void setOverwriteMode( OverwriteMode mode )
const BitInFormat & detectedFormat() const noexcept
BitPropVariant archiveProperty( BitProperty property ) const
BitPropVariant itemProperty( uint32_t index, BitProperty property ) const
uint32_t itemsCount() const
bool isItemFolder( uint32_t index ) const
bool isItemEncrypted( uint32_t index ) const
const tstring & archivePath() const noexcept
const BitAbstractArchiveHandler & handler() const noexcept
void extract( const tstring& out_dir, const std::vector< uint32_t >& indices = {} ) const
void extract( std::vector< byte_t >& out_buffer, uint32_t index = 0 ) const
void extract( std::array< byte_t, N >& buffer, uint32_t index = 0 ) const
void extract( byte_t( &buffer )[N], uint32_t index = 0 ) const
void extract( byte_t* buffer, std::size_t size, uint32_t index = 0 ) const
void extract( std::ostream& out_stream, uint32_t index = 0 ) const
void extract( std::map< tstring, std::vector< byte_t > >& out_map ) const
void test() const
BitInputArchive::const_iterator begin() const noexcept
BitInputArchive::const_iterator end() const noexcept
BitInputArchive::const_iterator cbegin() const noexcept
BitInputArchive::const_iterator cend() const noexcept
BitInputArchive::const_iterator find( const tstring& path ) const noexcept
bool contains( const tstring& path ) const noexcept

Member Function Documentation

BitArchiveReader( const Bit7zLibrary& lib, const tstring& in_archive, const BitInFormat& format = BitFormat::Auto, const tstring& password = {} )

Constructs a BitArchiveReader object, opening the input file archive.

Note: When bit7z is compiled using the BIT7Z_AUTO_FORMAT option, the format argument has default value BitFormat::Auto (automatic format detection of the input archive). On the contrary, when BIT7Z_AUTO_FORMAT is not defined (i.e., no auto format detection available), the format argument must be specified.

Parameters:

  • lib: the 7z library used.
  • in_archive: the path to the archive to be read.
  • format: the format of the input archive.
  • password: the password needed for opening the input archive.

BitArchiveReader( const Bit7zLibrary& lib, const std::vector< byte_t >& in_archive, const BitInFormat& format = BitFormat::Auto, const tstring& password = {} )

Constructs a BitArchiveReader object, opening the archive in the input buffer.

Note: When bit7z is compiled using the BIT7Z_AUTO_FORMAT option, the format argument has default value BitFormat::Auto (automatic format detection of the input archive). On the contrary, when BIT7Z_AUTO_FORMAT is not defined (i.e., no auto format detection available), the format argument must be specified.

Parameters:

  • lib: the 7z library used.
  • in_archive: the input buffer containing the archive to be read.
  • format: the format of the input archive.
  • password: the password needed for opening the input archive.

BitArchiveReader( const Bit7zLibrary& lib, std::istream& in_archive, const BitInFormat& format = BitFormat::Auto, const tstring& password = {} )

Constructs a BitArchiveReader object, opening the archive from the standard input stream.

Note: When bit7z is compiled using the BIT7Z_AUTO_FORMAT option, the format argument has default value BitFormat::Auto (automatic format detection of the input archive). On the contrary, when BIT7Z_AUTO_FORMAT is not defined (i.e., no auto format detection available), the format argument must be specified.

Parameters:

  • lib: the 7z library used.
  • in_archive: the standard input stream of the archive to be read.
  • format: the format of the input archive.
  • password: the password needed for opening the input archive.

~BitArchiveReader() override = default

BitArchiveReader destructor.

Note: It releases the input archive file.

map< BitProperty, BitPropVariant > archiveProperties() const

Returns a map of all the available (i.e., non-empty) archive properties and their respective values.

vector< BitArchiveItemInfo > items() const

Returns a vector of all the archive items as BitArchiveItem objects.

uint32_t foldersCount() const

Returns the number of folders contained in the archive.

uint32_t filesCount() const

Returns the number of files contained in the archive.

uint64_t size() const

Returns the total uncompressed size of the archive content.

uint64_t packSize() const

Returns the total compressed size of the archive content.

bool hasEncryptedItems() const

Returns true if and only if the archive has at least one encrypted item.

uint32_t volumesCount() const

Returns the number of volumes composing the archive.

bool isMultiVolume() const

Returns true if and only if the archive is composed by multiple volumes.

bool isSolid() const

Returns true if and only if the archive was created using solid compression.

[virtual] const BitInFormat & format() const noexcept override

Returns the archive format used by the archive opener.

const BitInFormat & extractionFormat() const noexcept

Returns the archive format used by the archive opener.

const Bit7zLibrary & library() const noexcept

Returns the Bit7zLibrary object used by the handler.

tstring password() const

Returns the password used to open, extract, or encrypt the archive.

bool retainDirectories() const noexcept

Returns a boolean value indicating whether the directory structure must be preserved while extracting or compressing the archive.

bool isPasswordDefined() const noexcept

Returns a boolean value indicating whether a password is defined or not.

TotalCallback totalCallback() const

Returns the current total callback.

ProgressCallback progressCallback() const

Returns the current progress callback.

RatioCallback ratioCallback() const

Returns the current ratio callback.

FileCallback fileCallback() const

Returns the current file callback.

PasswordCallback passwordCallback() const

Returns the current password callback.

OverwriteMode overwriteMode() const

Returns the current OverwriteMode.

[virtual] void setPassword( const tstring& password )

Sets up a password to be used by the archive handler. The password will be used to encrypt/decrypt archives by using the default cryptographic method of the archive format.

Note: Calling setPassword when the input archive is not encrypted does not have any effect on the extraction process.

Parameters:

  • password: the password to be used.

void clearPassword() noexcept

Clear the current password used by the handler. Calling clearPassword() will disable the encryption/decryption of archives.

Note: This is equivalent to calling setPassword(L"").

void setRetainDirectories( bool retain ) noexcept

Sets whether the operations' output will preserve the input's directory structure or not.

Parameters:

  • retain: the setting for preserving or not the input directory structure

void setTotalCallback( const TotalCallback& callback )

Sets the function to be called when the total size of an operation is available.

Parameters:

  • callback: the total callback to be used.

void setProgressCallback( const ProgressCallback& callback )

Sets the function to be called when the processed size of the ongoing operation is updated.

Note: The completion percentage of the current operation can be obtained by calculating static_cast<int>( ( 100.0 * processed_size ) / total_size ).

Parameters:

  • callback: the progress callback to be used.

void setRatioCallback( const RatioCallback& callback )

Sets the function to be called when the input processed size and current output size of the ongoing operation are known.

Note: The ratio percentage of a compression operation can be obtained by calculating static_cast<int>( ( 100.0 * output_size ) / input_size ).

Parameters:

  • callback: the ratio callback to be used.

void setFileCallback( const FileCallback& callback )

Sets the function to be called when the current file being processed changes.

Parameters:

  • callback: the file callback to be used.

void setPasswordCallback( const PasswordCallback& callback )

Sets the function to be called when a password is needed to complete the ongoing operation.

Parameters:

  • callback: the password callback to be used.

void setOverwriteMode( OverwriteMode mode )

Sets how the handler should behave when it tries to output to an existing file or buffer.

Parameters:

const BitInFormat & detectedFormat() const noexcept

Returns the detected format of the file.

BitPropVariant archiveProperty( BitProperty property ) const

Gets the specified archive property.

Parameters:

  • property: the property to be retrieved.

Returns the current value of the archive property or an empty BitPropVariant if no value is specified.

BitPropVariant itemProperty( uint32_t index, BitProperty property ) const

Gets the specified property of an item in the archive.

Parameters:

  • index: the index (in the archive) of the item.
  • property: the 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.

uint32_t itemsCount() const

Returns the number of items contained in the archive.

bool isItemFolder( uint32_t index ) const

Parameters:

  • index: the index of an item in the archive.

Returns true if and only if the item at the given index is a folder.

bool isItemEncrypted( uint32_t index ) const

Parameters:

  • index: the index of an item in the archive.

Returns true if and only if the item at the given index is encrypted.

const tstring & archivePath() const noexcept

Returns the path to the archive (the empty string for buffer/stream archives).

const BitAbstractArchiveHandler & handler() const noexcept

Returns the BitAbstractArchiveHandler object containing the settings for reading the archive.

void extract( const tstring& out_dir, const std::vector< uint32_t >& indices = {} ) const

Extracts the specified items to the chosen directory.

Parameters:

  • out_dir: the output directory where the extracted files will be put.
  • indices: the array of indices of the files in the archive that must be extracted.

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

Extracts a file to the output buffer.

Parameters:

  • out_buffer: the output buffer where the content of the archive will be put.
  • index: the index of the file to be extracted.

void extract( std::array< byte_t, N >& buffer, uint32_t index = 0 ) const

Extracts a file to the pre-allocated output buffer.

Parameters:

  • buffer: the pre-allocated output buffer.
  • index: the index of the file to be extracted.

void extract( byte_t(&) buffer, uint32_t index = 0 ) const

Extracts a file to the pre-allocated output buffer.

Parameters:

  • buffer: the pre-allocated output buffer.
  • index: the index of the file to be extracted.

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

Extracts a file to the pre-allocated output buffer.

Parameters:

  • buffer: the pre-allocated output buffer.
  • size: the size of the output buffer (it must be equal to the unpacked size of the item to be extracted).
  • index: the index of the file to be extracted.

void extract( std::ostream& out_stream, uint32_t index = 0 ) const

Extracts a file to the output stream.

Parameters:

  • out_stream: the (binary) stream where the content of the archive will be put.
  • index: the index of the file to be extracted.

void extract( std::map< tstring, std::vector< byte_t > >& out_map ) 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:

  • out_map: the output map.

void test() const

Tests the archive without extracting its content. If the archive is not valid, a BitException is thrown!

BitInputArchive::const_iterator begin() const 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.

BitInputArchive::const_iterator end() const 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.

BitInputArchive::const_iterator cbegin() const 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.

BitInputArchive::const_iterator cend() const 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.

BitInputArchive::const_iterator find( const tstring& path ) const noexcept

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

Parameters:

  • path: the 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.

bool contains( const tstring& path ) const noexcept

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

Parameters:

  • path: the path to be searched in the archive.

Returns true if and only if an item with the given path exists in the archive.

Clone this wiki locally