libassetmap  1.0.0
Hash-table based archive format containing compressed data
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
AssetMap::ZSTD Class Reference
Inheritance diagram for AssetMap::ZSTD:
Inheritance graph
[legend]
Collaboration diagram for AssetMap::ZSTD:
Collaboration graph
[legend]

Public Member Functions

 ZSTD (both_t, float dictRatio=0.01f)
 Construct an instance of ZSTD for compression and decompression. More...
 
 ZSTD (compress_t, float dictRatio=0.01f)
 Construct an instance of ZSTD for compression. More...
 
 ZSTD (decompress_t)
 Construct an instance of ZSTD for decompression. More...
 
 ZSTD (const ZSTD &)=delete
 
 ZSTD (ZSTD &&rhs) noexcept
 
ZSTD & operator= (ZSTD &&rhs) noexcept
 
size_t Compress (const uint8_t *src, size_t srcLen, uint8_t *dst, size_t dstLen) override
 Compresses data from src into dst. More...
 
size_t Decompress (const uint8_t *src, size_t srcLen, uint8_t *dst, size_t dstLen) override
 Decompresses data from src into dst. More...
 
size_t CalcCompressSize (size_t len) const noexcept override
 Calculates the worst-case size needed to compress the data. More...
 
size_t CalcDecompressSize (const uint8_t *src, size_t len) const noexcept override
 Calculates the number of bytes needed to decompress the data. More...
 
bool CreateDictionary (std::filesystem::directory_entry samplesDir) override
 Creates a dictionary from a directory of samples. More...
 
void UseDictionary (const uint8_t *dict, size_t len) noexcept override
 References a dictionary for (de)compression purposes. More...
 
void UseDictionary (std::filesystem::directory_entry ent)
 Reads a file into memory and uses it as a dictionary. More...
 
void SetCompressLevel (int level) noexcept
 Sets the desired compression level. More...
 
void SetStrategyLevel (int level) noexcept
 
std::pair< const uint8_t *, size_t > Dictionary () const noexcept override
 

Static Public Member Functions

static int MinCompressLevel () noexcept
 
static int MaxCompressLevel () noexcept
 
static int DefaultCompressLevel () noexcept
 
static int MinStrategyLevel () noexcept
 
static int MaxStrategyLevel () noexcept
 
static const char * StrategyInfo () noexcept
 

Static Public Attributes

static constexpr compress_t compress {}
 
static constexpr decompress_t decompress {}
 
static constexpr both_t both {}
 

Constructor & Destructor Documentation

◆ ZSTD() [1/3]

AssetMap::ZSTD::ZSTD ( both_t  ,
float  dictRatio = 0.01f 
)
explicit

Construct an instance of ZSTD for compression and decompression.

Parameters
dictRatiooptionally specifies the desired dictionary size. defaults to 1% (0.01)

◆ ZSTD() [2/3]

AssetMap::ZSTD::ZSTD ( compress_t  ,
float  dictRatio = 0.01f 
)
explicit

Construct an instance of ZSTD for compression.

Postcondition
Attempting to decompress data results in undefined behaviour.
Parameters
dictRatiooptionally specifies the desired dictionary size. defaults to 1% (0.01)

◆ ZSTD() [3/3]

AssetMap::ZSTD::ZSTD ( decompress_t  )
explicit

Construct an instance of ZSTD for decompression.

Postcondition
Attempting to compress data results in undefined behaviour.
Parameters
dictRatiooptionally specifies the desired dictionary size. defaults to 1% (0.01)

Member Function Documentation

◆ CalcCompressSize()

size_t AssetMap::ZSTD::CalcCompressSize ( size_t  len) const
overridevirtualnoexcept

Calculates the worst-case size needed to compress the data.

Parameters
lenThe size of the input data
Returns
The worst-case space requirement to compress the data.

Implements AssetMap::ICompress.

◆ CalcDecompressSize()

size_t AssetMap::ZSTD::CalcDecompressSize ( const uint8_t *  src,
size_t  len 
) const
overridevirtualnoexcept

Calculates the number of bytes needed to decompress the data.

Precondition
If a dictionary was used to compress the data, it must have been loaded.
Parameters
srcA pointer to the input data.
lenthe size (in bytes) of the input data.
Returns
The number of bytes required to fully decompress the data.

Implements AssetMap::IDecompress.

◆ Compress()

size_t AssetMap::ZSTD::Compress ( const uint8_t *  src,
size_t  srcLen,
uint8_t *  dst,
size_t  dstLen 
)
overridevirtual

Compresses data from src into dst.

Parameters
srcThe source buffer to compress data from.
srcLenThe length in bytes to compress.
dstThe destination buffer to place compressed data in.
dstLenThe total space available. Should be at least CalcCompressSize()
Returns
The number of bytes written into the destination.

Implements AssetMap::ICompress.

◆ CreateDictionary()

bool AssetMap::ZSTD::CreateDictionary ( std::filesystem::directory_entry  samplesDir)
overridevirtual

Creates a dictionary from a directory of samples.

A non-trivial amount of memory is typically required to generate a dictionary. All samples are copied into memory.

Parameters
samplesDirA valid directory that will be iterated recursively.
Returns
Whether or not a dictionary was created. It is not an error if dictionary creation fails; dive into zdict's implementation if you feel it shouldn't have failed.

Implements AssetMap::ICompress.

◆ Decompress()

size_t AssetMap::ZSTD::Decompress ( const uint8_t *  src,
size_t  srcLen,
uint8_t *  dst,
size_t  dstLen 
)
overridevirtual

Decompresses data from src into dst.

Precondition
If the data was compressed with a dictionary, it must have been loaded.
Parameters
srcThe source buffer to decompress data from.
srcLenThe length in bytes to decompress.
dstThe destination buffer to place decompressed data in.
dstLenThe total space available. Ideally at least CalcDecompressSize()
Returns
The number of bytes written into the destination.

Implements AssetMap::IDecompress.

◆ DefaultCompressLevel()

static int AssetMap::ZSTD::DefaultCompressLevel ( )
staticnoexcept
Returns
The default library's compression level.

◆ Dictionary()

std::pair<const uint8_t*, size_t> AssetMap::ZSTD::Dictionary ( ) const
overridevirtualnoexcept
Returns
a pair containing a pointer to the dictionary and its size. the pointer will be nullptr if no dictionary was loaded.

Implements AssetMap::ICompress.

◆ MaxCompressLevel()

static int AssetMap::ZSTD::MaxCompressLevel ( )
staticnoexcept
Returns
The maximum compression level.

◆ MaxStrategyLevel()

static int AssetMap::ZSTD::MaxStrategyLevel ( )
staticnoexcept
Returns
The maximum strategy level

◆ MinCompressLevel()

static int AssetMap::ZSTD::MinCompressLevel ( )
staticnoexcept
Returns
The minimum compression level. Usually a large negative value.

◆ MinStrategyLevel()

static int AssetMap::ZSTD::MinStrategyLevel ( )
staticnoexcept
Returns
The minimum strategy level.

◆ SetCompressLevel()

void AssetMap::ZSTD::SetCompressLevel ( int  level)
noexcept

Sets the desired compression level.

Precondition
If a dictionary has been loaded, has no effect. Otherwise, all future compression and dictionary creation uses this.
Parameters
levelThe desired compression level. Must be in the range MinCompressionLevel() <= level <= MaxCompressLevel()

◆ SetStrategyLevel()

void AssetMap::ZSTD::SetStrategyLevel ( int  level)
noexcept

Sets the desired compression strategy.

Parameters
levelthe strategy to use. Must be in the range MinStrategyLevel() <= level <= MaxStrategyLevel()

◆ StrategyInfo()

static const char* AssetMap::ZSTD::StrategyInfo ( )
staticnoexcept
Returns
a human-readable string containing all strategies

◆ UseDictionary() [1/2]

void AssetMap::ZSTD::UseDictionary ( const uint8_t *  dict,
size_t  len 
)
overridevirtualnoexcept

References a dictionary for (de)compression purposes.

Postcondition
The dictionary must remain valid for the lifetime of this instance.
Parameters
dictA buffer containing the dictionary to load.
lenThe size of the dictionary (in bytes)

Implements AssetMap::ICompress.

◆ UseDictionary() [2/2]

void AssetMap::ZSTD::UseDictionary ( std::filesystem::directory_entry  ent)

Reads a file into memory and uses it as a dictionary.

This function mainly exists for convenience; it is recommended to mmap the dictionary and use the non-owning overload.

Parameters
entA valid, regular file to read the dictionary from.

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