Pack v2.0.4
Reader Class Referencefinal

Pack reader instance handle. More...

#include <reader.hpp>

Public Member Functions

 Reader ()=default
 Creates a new file pack reader without stream.
 
 Reader (const Reader &)=delete
 
 Reader (Reader &&r) noexcept
 
Readeroperator= (Reader &)=delete
 
Readeroperator= (Reader &&r) noexcept
 
 Reader (const filesystem::path &filePath, bool isResourcesDirectory=true, uint32_t threadCount=thread::hardware_concurrency())
 Creates a new file pack reader instance.
 
 ~Reader ()
 Destroys pack reader stream.
 
void open (const filesystem::path &filePath, bool isResourcesDirectory=true, uint32_t threadCount=thread::hardware_concurrency())
 Opens a new Pack reader stream.
 
void close () noexcept
 Closes the current Pack reader stream.
 
bool isOpen () const noexcept
 Returns true if Pack reader stream is open.
 
uint64_t getItemCount () const noexcept
 Returns total Pack item count. (MT-Safe)
 
bool getItemIndex (const filesystem::path &path, uint64_t &index) const noexcept
 Returns Pack item index if it is found. (MT-Safe)
 
uint64_t getItemIndex (const filesystem::path &path) const
 Returns Pack item index. (MT-Safe)
 
uint32_t getItemDataSize (uint64_t index) const noexcept
 Returns Pack item uncompressed data size in bytes. (MT-Safe)
 
uint32_t getItemZipSize (uint64_t index) const noexcept
 Returns Pack item compressed data size in bytes. (MT-Safe)
 
void readItemData (uint64_t itemIndex, uint8_t *buffer, uint32_t threadIndex=0) const
 Reads Pack item binary data. (MT-Safe)
 
void readItemData (uint64_t itemIndex, vector< uint8_t > &buffer, uint32_t threadIndex=0) const
 Reads Pack item binary data. (MT-Safe)
 
void readItemData (const filesystem::path &path, vector< uint8_t > &buffer, uint32_t threadIndex=0) const
 Reads Pack item binary data. (MT-Safe)
 
uint64_t getItemFileOffset (uint64_t index) const noexcept
 Returns Pack item data offset in the archive file. (MT-Safe)
 
bool isItemReference (uint64_t index) const noexcept
 Returns true if pack item is a reference to a duplicate item. (MT-Safe)
 
string_view getItemPath (uint64_t index) const noexcept
 Returns Pack item path string. (MT-Safe)
 
void **const getZstdContexts () const
 Returns Pack ZSTD context array. (MT-Safe)
 

Static Public Member Functions

static void unpack (const filesystem::path &filePath, bool printProgress=false)
 Unpacks files from the pack. (MT-Safe)
 

Detailed Description

Pack reader instance handle.

See the reader.h

Constructor & Destructor Documentation

◆ Reader()

Reader ( const filesystem::path & filePath,
bool isResourcesDirectory = true,
uint32_t threadCount = thread::hardware_concurrency() )
inline

Creates a new file pack reader instance.

See the createFilePackReader().

Parameters
[in]filePathtarget Pack file path string
isResourcesDirectoryread from the resources directory (Android/iOS/macOS only)
threadCountmax concurrent read thread count
Exceptions
Errorwith a PackResult string on failure.

◆ ~Reader()

~Reader ( )
inline

Destroys pack reader stream.

See the destroyPackReader().

Member Function Documentation

◆ open()

void open ( const filesystem::path & filePath,
bool isResourcesDirectory = true,
uint32_t threadCount = thread::hardware_concurrency() )
inline

Opens a new Pack reader stream.

See the createFilePackReader().

Parameters
[in]filePathtarget Pack file path string
isResourcesDirectoryread from the resources directory (Android/iOS/macOS only)
threadCountmax concurrent read thread count
Exceptions
Errorwith a PackResult string on failure.

◆ close()

void close ( )
inlinenoexcept

Closes the current Pack reader stream.

See the destroyPackReader().

◆ isOpen()

bool isOpen ( ) const
inlinenoexcept

Returns true if Pack reader stream is open.

See the createFilePackReader().

◆ getItemCount()

uint64_t getItemCount ( ) const
inlinenoexcept

Returns total Pack item count. (MT-Safe)

See the getPackItemCount().

Returns
The total number of the items inside Pack file.

◆ getItemIndex() [1/2]

bool getItemIndex ( const filesystem::path & path,
uint64_t & index ) const
inlinenoexcept

Returns Pack item index if it is found. (MT-Safe)

See the getPackItemIndex().

Parameters
[in]pathitem path string used to pack the file
[out]indexreference to the uint64_t item index
Returns
True if item is found and writes index value, otherwise false.

◆ getItemIndex() [2/2]

uint64_t getItemIndex ( const filesystem::path & path) const
inline

Returns Pack item index. (MT-Safe)

See the getPackItemIndex().

Parameters
[in]pathitem path string used to pack the file
Returns
The item index in the Pack.
Exceptions
Errorif item does not exist.

◆ getItemDataSize()

uint32_t getItemDataSize ( uint64_t index) const
inlinenoexcept

Returns Pack item uncompressed data size in bytes. (MT-Safe)

See the getPackItemDataSize().

Parameters
indexuint64_t item index
Returns
The data binary size.

◆ getItemZipSize()

uint32_t getItemZipSize ( uint64_t index) const
inlinenoexcept

Returns Pack item compressed data size in bytes. (MT-Safe)

See the getPackItemZipSize().

Parameters
indexuint64_t item index
Returns
The data binary size, or 0 if item is not compressed.

◆ readItemData() [1/3]

void readItemData ( uint64_t itemIndex,
uint8_t * buffer,
uint32_t threadIndex = 0 ) const
inline

Reads Pack item binary data. (MT-Safe)

See the readPackItemData().

Parameters
itemIndexuint64_t item index
[out]bufferpointer to the buffer where to read item data
threadIndexcurrent thread index or 0
Exceptions
Errorwith a PackResult string on failure.

◆ readItemData() [2/3]

void readItemData ( uint64_t itemIndex,
vector< uint8_t > & buffer,
uint32_t threadIndex = 0 ) const
inline

Reads Pack item binary data. (MT-Safe)

See the readPackItemData().

Parameters
itemIndexuint64_t item index
[out]bufferreference to the buffer where to read item data
threadIndexcurrent thread index or 0
Exceptions
Errorwith a PackResult string on failure.

◆ readItemData() [3/3]

void readItemData ( const filesystem::path & path,
vector< uint8_t > & buffer,
uint32_t threadIndex = 0 ) const
inline

Reads Pack item binary data. (MT-Safe)

See the readPackItemData().

Parameters
[in]pathitem path string used to pack the file
[out]bufferreference to the buffer where to read item data
threadIndexcurrent thread index or 0
Exceptions
Errorwith a PackResult string on failure.

◆ getItemFileOffset()

uint64_t getItemFileOffset ( uint64_t index) const
inlinenoexcept

Returns Pack item data offset in the archive file. (MT-Safe)

See the getPackItemFileOffset().

Parameters
indexuint64_t item index
Returns
The data offset in the file.

◆ isItemReference()

bool isItemReference ( uint64_t index) const
inlinenoexcept

Returns true if pack item is a reference to a duplicate item. (MT-Safe)

See the isPackItemReference().

Parameters
indexuint64_t item index
Returns
True if item is a reference, otherwise false.

◆ getItemPath()

string_view getItemPath ( uint64_t index) const
inlinenoexcept

Returns Pack item path string. (MT-Safe)

See the getPackItemPath().

Parameters
indexuint64_t item index
Returns
The Pack item path sting.

◆ getZstdContexts()

void **const getZstdContexts ( ) const
inline

Returns Pack ZSTD context array. (MT-Safe)

See the getPackZstdContexts().

Returns
Array of the ZSTD_DCtx* contexts.

◆ unpack()

static void unpack ( const filesystem::path & filePath,
bool printProgress = false )
inlinestatic

Unpacks files from the pack. (MT-Safe)

See the unpackFiles().

Parameters
[in]filePathtarget Pack file path string
printProgressoutput unpacking progress to the stdout
Exceptions
Errorwith a PackResult string on failure.