|
libassetmap
1.0.0
Hash-table based archive format containing compressed data
|
1 #ifndef LIBASSETMAP_ZSTDCOMP_H
2 #define LIBASSETMAP_ZSTDCOMP_H
5 #include "IDecompress.h"
9 using ZSTD_CCtx =
struct ZSTD_CCtx_s;
10 using ZSTD_DCtx =
struct ZSTD_DCtx_s;
11 using ZSTD_CDict =
struct ZSTD_CDict_s;
12 using ZSTD_DDict =
struct ZSTD_DDict_s;
24 constexpr ZCtx() =
default;
25 constexpr ZCtx(ZCtx&&) noexcept;
26 constexpr ZCtx& operator=(ZCtx&&) noexcept;
27 constexpr ZCtx& operator=(Ctx* ctx) noexcept;
28 constexpr explicit operator
bool() const noexcept;
29 operator Ctx*() const noexcept;
30 constexpr
void Create();
37 const uint8_t* dictionary =
nullptr;
39 int compressionLevel = 0;
40 float dictRatio = 0.01f;
41 std::vector<uint8_t> generatedDictionary;
44 struct decompress_t {};
47 ZSTD(
float dictRatio) noexcept;
50 static constexpr compress_t compress{};
51 static constexpr decompress_t decompress{};
52 static constexpr both_t both{};
58 explicit ZSTD(both_t,
float dictRatio = 0.01f);
65 explicit ZSTD(compress_t,
float dictRatio = 0.01f);
72 explicit ZSTD(decompress_t);
78 ZSTD& operator=(
ZSTD&& rhs) noexcept;
87 [[nodiscard]]
size_t Compress(
const uint8_t* src,
90 size_t dstLen)
override;
104 size_t dstLen)
override;
118 size_t len)
const noexcept
override;
162 static
int MaxCompressLevel() noexcept;
165 static
int DefaultCompressLevel() noexcept;
168 static
int MinStrategyLevel() noexcept;
171 static
int MaxStrategyLevel() noexcept;
174 static const
char* StrategyInfo() noexcept;
178 [[nodiscard]] std::pair<const uint8_t*,
size_t>
179 Dictionary() const noexcept override;
181 ~
ZSTD() noexcept override;
185 #endif // LIBASSETMAP_ZSTDCOMP_H
ZSTD(compress_t, float dictRatio=0.01f)
Construct an instance of ZSTD for compression.
size_t CalcDecompressSize(const uint8_t *src, size_t len) const noexcept override
Calculates the number of bytes needed to decompress the data.
Definition: IDecompress.h:10
static int MinCompressLevel() noexcept
void SetStrategyLevel(int level) noexcept
Definition: ICompress.h:10
ZSTD(both_t, float dictRatio=0.01f)
Construct an instance of ZSTD for compression and decompression.
size_t Decompress(const uint8_t *src, size_t srcLen, uint8_t *dst, size_t dstLen) override
Decompresses data from src into dst.
void UseDictionary(const uint8_t *dict, size_t len) noexcept override
References a dictionary for (de)compression purposes.
void UseDictionary(std::filesystem::directory_entry ent)
Reads a file into memory and uses it as a dictionary.
bool CreateDictionary(std::filesystem::directory_entry samplesDir) override
Creates a dictionary from a directory of samples.
size_t CalcCompressSize(size_t len) const noexcept override
Calculates the worst-case size needed to compress the data.
size_t Compress(const uint8_t *src, size_t srcLen, uint8_t *dst, size_t dstLen) override
Compresses data from src into dst.
void SetCompressLevel(int level) noexcept
Sets the desired compression level.
Definition: DirectoryMetadata.h:65
ZSTD(decompress_t)
Construct an instance of ZSTD for decompression.
Definition: ZSTDComp.h:34