Pack v2.0.4
common.h File Reference

Common Pack library functions. More...

#include "pack/defines.h"
#include <stdbool.h>

Data Structures

struct  PackHeader
 Pack file header structure. More...
 
struct  PackItemHeader
 Pack item header structure. More...
 

Macros

#define PACK_HEADER_MAGIC   (('P' << 24) | ('A' << 16) | ('C' << 8) | 'K')
 Pack file header magic number.
 

Typedefs

typedef uint8_t PackResult
 Pack result code type.
 

Enumerations

enum  PackResult_T {
  SUCCESS_PACK_RESULT = 0 , FAILED_TO_ALLOCATE_PACK_RESULT = 1 , FAILED_TO_CREATE_ZSTD_PACK_RESULT = 2 , FAILED_TO_CREATE_FILE_PACK_RESULT = 3 ,
  FAILED_TO_OPEN_FILE_PACK_RESULT = 4 , FAILED_TO_WRITE_FILE_PACK_RESULT = 5 , FAILED_TO_READ_FILE_PACK_RESULT = 6 , FAILED_TO_SEEK_FILE_PACK_RESULT = 7 ,
  FAILED_TO_GET_DIRECTORY_PACK_RESULT = 8 , FAILED_TO_DECOMPRESS_PACK_RESULT = 9 , FAILED_TO_GET_ITEM_PACK_RESULT = 10 , BAD_DATA_SIZE_PACK_RESULT = 11 ,
  BAD_FILE_TYPE_PACK_RESULT = 12 , BAD_FILE_VERSION_PACK_RESULT = 13 , BAD_FILE_ENDIANNESS_PACK_RESULT = 14 , PACK_RESULT_COUNT = 15
}
 

Functions

void getPackLibraryVersion (uint8_t *major, uint8_t *minor, uint8_t *patch)
 Returns Pack library hardcoded version. (MT-Safe)
 
PackResult readPackHeader (const char *filePath, PackHeader *header)
 Reads Pack header from the file. (MT-Safe)
 

Detailed Description

Common Pack library functions.


Data Structure Documentation

◆ PackHeader

struct PackHeader

Pack file header structure.

Each Pack file begins with a header that contains information about the library and system used for packing the files. It also contains the total number of files inside the archive.

Data Fields
uint32_t magic

Pack file magic number

uint8_t versionMajor

File format major version

uint8_t versionMinor

File format minor version

uint8_t versionPatch

File format patch version

uint8_t isBigEndian

Is packed data format big endian

uint64_t itemCount

Total pack itrm count

◆ PackItemHeader

struct PackItemHeader

Pack item header structure.

Contains information about the packed file inside the archive. This includes the size of its path, the size of compressed data, whether data are compressed, and the location of the data within the archive file.

Data Fields
uint32_t zipSize

Compressed item size in bytes

uint32_t dataSize

Uncompressed item size in bytes

uint8_t pathSize: 8

Item path string length

uint8_t isReference: 1

Is binary data shared between several items

uint64_t dataOffset: 55

Binary data offset in the Pack file

Function Documentation

◆ getPackLibraryVersion()

void getPackLibraryVersion ( uint8_t * major,
uint8_t * minor,
uint8_t * patch )

Returns Pack library hardcoded version. (MT-Safe)

Useful in cases when we load a dynamic Pack library (.dll) or use it from another programming language. (ex. C#, Java)

Parameters
[out]majorpointer to the uint32_t major version
[out]minorpointer to the uint32_t minor version
[out]patchpointer to the uint32_t patch version

◆ readPackHeader()

PackResult readPackHeader ( const char * filePath,
PackHeader * header )

Reads Pack header from the file. (MT-Safe)

We can retrieve information about the package without creating an instance and loading the paths of all packed files.

Parameters
[in]filePathtarget file path string
[out]headerpointer to the PackHeader structure
Returns
The PackResult code.
Return values
SUCCESS_PACK_RESULTon success
FAILED_TO_OPEN_FILE_PACK_RESULTif file doesn't exist
BAD_FILE_TYPE_PACK_RESULTif file header has bad magic number