1*0c16b537SWarner Losh /* 2*0c16b537SWarner Losh * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3*0c16b537SWarner Losh * All rights reserved. 4*0c16b537SWarner Losh * 5*0c16b537SWarner Losh * This source code is licensed under both the BSD-style license (found in the 6*0c16b537SWarner Losh * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7*0c16b537SWarner Losh * in the COPYING file in the root directory of this source tree). 8*0c16b537SWarner Losh * You may select, at your option, one of the above-listed licenses. 9*0c16b537SWarner Losh */ 10*0c16b537SWarner Losh 11*0c16b537SWarner Losh 12*0c16b537SWarner Losh 13*0c16b537SWarner Losh /* ************************************* 14*0c16b537SWarner Losh * Dependencies 15*0c16b537SWarner Losh ***************************************/ 16*0c16b537SWarner Losh #define ZBUFF_STATIC_LINKING_ONLY 17*0c16b537SWarner Losh #include "zbuff.h" 18*0c16b537SWarner Losh 19*0c16b537SWarner Losh 20*0c16b537SWarner Losh ZBUFF_DCtx* ZBUFF_createDCtx(void) 21*0c16b537SWarner Losh { 22*0c16b537SWarner Losh return ZSTD_createDStream(); 23*0c16b537SWarner Losh } 24*0c16b537SWarner Losh 25*0c16b537SWarner Losh ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem) 26*0c16b537SWarner Losh { 27*0c16b537SWarner Losh return ZSTD_createDStream_advanced(customMem); 28*0c16b537SWarner Losh } 29*0c16b537SWarner Losh 30*0c16b537SWarner Losh size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd) 31*0c16b537SWarner Losh { 32*0c16b537SWarner Losh return ZSTD_freeDStream(zbd); 33*0c16b537SWarner Losh } 34*0c16b537SWarner Losh 35*0c16b537SWarner Losh 36*0c16b537SWarner Losh /* *** Initialization *** */ 37*0c16b537SWarner Losh 38*0c16b537SWarner Losh size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* zbd, const void* dict, size_t dictSize) 39*0c16b537SWarner Losh { 40*0c16b537SWarner Losh return ZSTD_initDStream_usingDict(zbd, dict, dictSize); 41*0c16b537SWarner Losh } 42*0c16b537SWarner Losh 43*0c16b537SWarner Losh size_t ZBUFF_decompressInit(ZBUFF_DCtx* zbd) 44*0c16b537SWarner Losh { 45*0c16b537SWarner Losh return ZSTD_initDStream(zbd); 46*0c16b537SWarner Losh } 47*0c16b537SWarner Losh 48*0c16b537SWarner Losh 49*0c16b537SWarner Losh /* *** Decompression *** */ 50*0c16b537SWarner Losh 51*0c16b537SWarner Losh size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbd, 52*0c16b537SWarner Losh void* dst, size_t* dstCapacityPtr, 53*0c16b537SWarner Losh const void* src, size_t* srcSizePtr) 54*0c16b537SWarner Losh { 55*0c16b537SWarner Losh ZSTD_outBuffer outBuff; 56*0c16b537SWarner Losh ZSTD_inBuffer inBuff; 57*0c16b537SWarner Losh size_t result; 58*0c16b537SWarner Losh outBuff.dst = dst; 59*0c16b537SWarner Losh outBuff.pos = 0; 60*0c16b537SWarner Losh outBuff.size = *dstCapacityPtr; 61*0c16b537SWarner Losh inBuff.src = src; 62*0c16b537SWarner Losh inBuff.pos = 0; 63*0c16b537SWarner Losh inBuff.size = *srcSizePtr; 64*0c16b537SWarner Losh result = ZSTD_decompressStream(zbd, &outBuff, &inBuff); 65*0c16b537SWarner Losh *dstCapacityPtr = outBuff.pos; 66*0c16b537SWarner Losh *srcSizePtr = inBuff.pos; 67*0c16b537SWarner Losh return result; 68*0c16b537SWarner Losh } 69*0c16b537SWarner Losh 70*0c16b537SWarner Losh 71*0c16b537SWarner Losh /* ************************************* 72*0c16b537SWarner Losh * Tool functions 73*0c16b537SWarner Losh ***************************************/ 74*0c16b537SWarner Losh size_t ZBUFF_recommendedDInSize(void) { return ZSTD_DStreamInSize(); } 75*0c16b537SWarner Losh size_t ZBUFF_recommendedDOutSize(void) { return ZSTD_DStreamOutSize(); } 76