|
◆ _gpak_decompressor_zstd()
GPAK_API uint32_t _gpak_decompressor_zstd |
( |
gpak_t * |
_pak, |
|
|
FILE * |
_infile, |
|
|
FILE * |
_outfile, |
|
|
size_t |
_read_size |
|
) |
| |
- Brief Description:\n Decompresses the input file using the Zstandard (zstd) algorithm.
- This function decompresses the input file using the Zstandard (zstd) algorithm and writes the decompressed data to the output file.
- Parameters
-
_pak | A pointer to the gpak_t. |
_infile | A pointer to the input FILE. |
_outfile | A pointer to the output FILE. |
_read_size | The number of bytes to read from the input file. |
- Returns
- The number of bytes written to the output file.
Definition at line 291 of file gpak_compressors.c.
293 size_t const buffInSize = ZSTD_DStreamInSize();
294 void* const buffIn = malloc(buffInSize);
295 size_t const buffOutSize = ZSTD_DStreamOutSize();
296 void* const buffOut = malloc(buffOutSize);
298 uint32_t _crc32 = crc32(0L, Z_NULL, 0);
300 ZSTD_DCtx* const dctx = ZSTD_createDCtx();
301 assert(dctx != NULL && "ZSTD_createDCtx() failed!");
306 size_t bytesRead = 0;
310 while (bytesRead < _read_size)
312 size_t const toRead = (bytesRead + buffInSize <= _read_size) ? buffInSize : (_read_size - bytesRead);
313 size_t read = _freadb(buffIn, 1, toRead, _infile);
325 ZSTD_inBuffer input = { buffIn, read, 0 };
326 while (input.pos < input.size)
328 ZSTD_outBuffer output = { buffOut, buffOutSize, 0 };
329 size_t const ret = ZSTD_decompressStream(dctx, &output, &input);
331 _crc32 = crc32(_crc32, buffOut, output.pos);
333 _fwriteb(buffOut, 1, output.pos, _outfile);
@ GPAK_ERROR_EOF_BEFORE_EOS
@ GPAK_STAGE_DECOMPRESSION
References gpak::dictionary_, gpak_header::dictionary_size_, GPAK_ERROR_EMPTY_INPUT, GPAK_ERROR_EOF_BEFORE_EOS, GPAK_STAGE_DECOMPRESSION, and gpak::header_.
Referenced by gpak_fopen().
|