zbuff_decompress.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  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 ZSTD_DISABLE_DEPRECATE_WARNINGS /* suppress warning on ZSTD_initDStream_usingDict */
  14. #include "../zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */
  15. #define ZBUFF_STATIC_LINKING_ONLY
  16. #include "zbuff.h"
  17. ZBUFF_DCtx* ZBUFF_createDCtx(void)
  18. {
  19. return ZSTD_createDStream();
  20. }
  21. ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem)
  22. {
  23. return ZSTD_createDStream_advanced(customMem);
  24. }
  25. size_t ZBUFF_freeDCtx(ZBUFF_DCtx* zbd)
  26. {
  27. return ZSTD_freeDStream(zbd);
  28. }
  29. /* *** Initialization *** */
  30. size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* zbd, const void* dict, size_t dictSize)
  31. {
  32. return ZSTD_initDStream_usingDict(zbd, dict, dictSize);
  33. }
  34. size_t ZBUFF_decompressInit(ZBUFF_DCtx* zbd)
  35. {
  36. return ZSTD_initDStream(zbd);
  37. }
  38. /* *** Decompression *** */
  39. size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbd,
  40. void* dst, size_t* dstCapacityPtr,
  41. const void* src, size_t* srcSizePtr)
  42. {
  43. ZSTD_outBuffer outBuff;
  44. ZSTD_inBuffer inBuff;
  45. size_t result;
  46. outBuff.dst = dst;
  47. outBuff.pos = 0;
  48. outBuff.size = *dstCapacityPtr;
  49. inBuff.src = src;
  50. inBuff.pos = 0;
  51. inBuff.size = *srcSizePtr;
  52. result = ZSTD_decompressStream(zbd, &outBuff, &inBuff);
  53. *dstCapacityPtr = outBuff.pos;
  54. *srcSizePtr = inBuff.pos;
  55. return result;
  56. }
  57. /* *************************************
  58. * Tool functions
  59. ***************************************/
  60. size_t ZBUFF_recommendedDInSize(void) { return ZSTD_DStreamInSize(); }
  61. size_t ZBUFF_recommendedDOutSize(void) { return ZSTD_DStreamOutSize(); }