xref: /freebsd-src/sys/contrib/zstd/lib/deprecated/zbuff_decompress.c (revision 5ff13fbc199bdf5f0572845351c68ee5ca828e71)
10c16b537SWarner Losh /*
2*5ff13fbcSAllan Jude  * Copyright (c) Yann Collet, Facebook, Inc.
30c16b537SWarner Losh  * All rights reserved.
40c16b537SWarner Losh  *
50c16b537SWarner Losh  * This source code is licensed under both the BSD-style license (found in the
60c16b537SWarner Losh  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
70c16b537SWarner Losh  * in the COPYING file in the root directory of this source tree).
80c16b537SWarner Losh  * You may select, at your option, one of the above-listed licenses.
90c16b537SWarner Losh  */
100c16b537SWarner Losh 
110c16b537SWarner Losh 
120c16b537SWarner Losh 
130c16b537SWarner Losh /* *************************************
140c16b537SWarner Losh *  Dependencies
150c16b537SWarner Losh ***************************************/
160c16b537SWarner Losh #define ZBUFF_STATIC_LINKING_ONLY
170c16b537SWarner Losh #include "zbuff.h"
180c16b537SWarner Losh 
190c16b537SWarner Losh 
ZBUFF_createDCtx(void)200c16b537SWarner Losh ZBUFF_DCtx* ZBUFF_createDCtx(void)
210c16b537SWarner Losh {
220c16b537SWarner Losh     return ZSTD_createDStream();
230c16b537SWarner Losh }
240c16b537SWarner Losh 
ZBUFF_createDCtx_advanced(ZSTD_customMem customMem)250c16b537SWarner Losh ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem)
260c16b537SWarner Losh {
270c16b537SWarner Losh     return ZSTD_createDStream_advanced(customMem);
280c16b537SWarner Losh }
290c16b537SWarner Losh 
ZBUFF_freeDCtx(ZBUFF_DCtx * zbd)300c16b537SWarner Losh size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd)
310c16b537SWarner Losh {
320c16b537SWarner Losh     return ZSTD_freeDStream(zbd);
330c16b537SWarner Losh }
340c16b537SWarner Losh 
350c16b537SWarner Losh 
360c16b537SWarner Losh /* *** Initialization *** */
370c16b537SWarner Losh 
ZBUFF_decompressInitDictionary(ZBUFF_DCtx * zbd,const void * dict,size_t dictSize)380c16b537SWarner Losh size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* zbd, const void* dict, size_t dictSize)
390c16b537SWarner Losh {
400c16b537SWarner Losh     return ZSTD_initDStream_usingDict(zbd, dict, dictSize);
410c16b537SWarner Losh }
420c16b537SWarner Losh 
ZBUFF_decompressInit(ZBUFF_DCtx * zbd)430c16b537SWarner Losh size_t ZBUFF_decompressInit(ZBUFF_DCtx* zbd)
440c16b537SWarner Losh {
450c16b537SWarner Losh     return ZSTD_initDStream(zbd);
460c16b537SWarner Losh }
470c16b537SWarner Losh 
480c16b537SWarner Losh 
490c16b537SWarner Losh /* *** Decompression *** */
500c16b537SWarner Losh 
ZBUFF_decompressContinue(ZBUFF_DCtx * zbd,void * dst,size_t * dstCapacityPtr,const void * src,size_t * srcSizePtr)510c16b537SWarner Losh size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbd,
520c16b537SWarner Losh                                 void* dst, size_t* dstCapacityPtr,
530c16b537SWarner Losh                           const void* src, size_t* srcSizePtr)
540c16b537SWarner Losh {
550c16b537SWarner Losh     ZSTD_outBuffer outBuff;
560c16b537SWarner Losh     ZSTD_inBuffer inBuff;
570c16b537SWarner Losh     size_t result;
580c16b537SWarner Losh     outBuff.dst  = dst;
590c16b537SWarner Losh     outBuff.pos  = 0;
600c16b537SWarner Losh     outBuff.size = *dstCapacityPtr;
610c16b537SWarner Losh     inBuff.src  = src;
620c16b537SWarner Losh     inBuff.pos  = 0;
630c16b537SWarner Losh     inBuff.size = *srcSizePtr;
640c16b537SWarner Losh     result = ZSTD_decompressStream(zbd, &outBuff, &inBuff);
650c16b537SWarner Losh     *dstCapacityPtr = outBuff.pos;
660c16b537SWarner Losh     *srcSizePtr = inBuff.pos;
670c16b537SWarner Losh     return result;
680c16b537SWarner Losh }
690c16b537SWarner Losh 
700c16b537SWarner Losh 
710c16b537SWarner Losh /* *************************************
720c16b537SWarner Losh *  Tool functions
730c16b537SWarner Losh ***************************************/
ZBUFF_recommendedDInSize(void)740c16b537SWarner Losh size_t ZBUFF_recommendedDInSize(void)  { return ZSTD_DStreamInSize(); }
ZBUFF_recommendedDOutSize(void)750c16b537SWarner Losh size_t ZBUFF_recommendedDOutSize(void) { return ZSTD_DStreamOutSize(); }
76