Skip to content

BitInputArchive

Oz edited this page Sep 25, 2024 · 8 revisions

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

#include <bit7z/bitinputarchive.hpp>

List of all members

Public Members

Return type Name
BitInputArchive( const BitAbstractArchiveHandler& handler, const fs::path& arcPath )
BitInputArchive( const BitAbstractArchiveHandler& handler, const std::vector< byte_t >& inBuffer )
BitInputArchive( const BitAbstractArchiveHandler& handler, const tstring& inFile )
BitInputArchive( const BitAbstractArchiveHandler& handler, std::istream& inStream )
const tstring & archivePath() const noexcept
BitPropVariant archiveProperty( BitProperty property ) const
BitInputArchive::ConstIterator begin() const noexcept
BitInputArchive::ConstIterator cbegin() const noexcept
BitInputArchive::ConstIterator cend() const noexcept
bool contains( const tstring& path ) const noexcept
const BitInFormat & detectedFormat() const noexcept
BitInputArchive::ConstIterator end() const noexcept
void extractTo( byte_t* buffer, std::size_t size, uint32_t index = 0 ) const
void extractTo( byte_t( &buffer )[N], uint32_t index = 0 ) const
void extractTo( const tstring& outDir ) const
void extractTo( const tstring& outDir, const std::vector< uint32_t >& indices ) const
void extractTo( std::array< byte_t, N >& buffer, uint32_t index = 0 ) const
void extractTo( std::map< tstring, std::vector< byte_t > >& outMap ) const
void extractTo( std::ostream& outStream, uint32_t index = 0 ) const
void extractTo( std::vector< byte_t >& outBuffer, uint32_t index = 0 ) const
BitInputArchive::ConstIterator find( const tstring& path ) const noexcept
const BitAbstractArchiveHandler & handler() const noexcept
bool isItemEncrypted( uint32_t index ) const
bool isItemFolder( uint32_t index ) const
BitArchiveItemOffset itemAt( uint32_t index ) const
BitPropVariant itemProperty( uint32_t index, BitProperty property ) const
uint32_t itemsCount() const
void test() const
void testItem( uint32_t index ) const

Member Function Documentation

BitInputArchive( const BitAbstractArchiveHandler& handler, const fs::path& arcPath )

Constructs a BitInputArchive object, opening the input file archive.

Parameters:

  • handler: the reference to the BitAbstractArchiveHandler object containing all the settings to be used for reading the input archive
  • arcPath: the path to the input archive file

BitInputArchive( const BitAbstractArchiveHandler& handler, const std::vector< byte_t >& inBuffer )

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

Parameters:

  • handler: the reference to the BitAbstractArchiveHandler object containing all the settings to be used for reading the input archive
  • inBuffer: the buffer containing the input archive

BitInputArchive( const BitAbstractArchiveHandler& handler, const tstring& inFile )

Constructs a BitInputArchive object, opening the input file archive.

Parameters:

  • handler: the reference to the BitAbstractArchiveHandler object containing all the settings to be used for reading the input archive
  • inFile: the path to the input archive file

BitInputArchive( const BitAbstractArchiveHandler& handler, std::istream& inStream )

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

Parameters:

  • handler: the reference to the BitAbstractArchiveHandler object containing all the settings to be used for reading the input archive
  • inStream: the standard input stream of the input archive

const tstring & archivePath() const noexcept

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


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.


BitInputArchive::ConstIterator 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::ConstIterator 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::ConstIterator 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.


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.


const BitInFormat & detectedFormat() const noexcept

Returns the detected format of the file.


BitInputArchive::ConstIterator 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.


void extractTo( 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 extractTo( 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 extractTo( const tstring& outDir ) const

Extracts the archive to the chosen directory.

Parameters:

  • outDir: the output directory where the extracted files will be put.

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

Extracts the specified items to the chosen directory.

Parameters:

  • outDir: 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 extractTo( 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 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:

  • outMap: the output map.

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

Extracts a file to the output stream.

Parameters:

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

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

Extracts a file to the output buffer.

Parameters:

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

BitInputArchive::ConstIterator 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.


const BitAbstractArchiveHandler & handler() const noexcept

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


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.


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.


BitArchiveItemOffset itemAt( uint32_t index ) const

Retrieve the item at the given index.

Parameters:

  • index: the index of the item to be retrieved.

Returns the item at the given index within the archive.


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.


void test() const

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


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:

  • index: the index of the file to be tested.

Clone this wiki locally