zbuff_decompress.c 1.9 KB

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