zstd_legacy.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #include <contrib/libs/zstd06/renames.h>
  2. /*
  3. zstd_legacy - decoder for legacy format
  4. Header File
  5. Copyright (C) 2015-2016, Yann Collet.
  6. BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are
  9. met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the following disclaimer
  14. in the documentation and/or other materials provided with the
  15. distribution.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. You can contact the author at :
  28. - zstd source repository : https://github.com/Cyan4973/zstd
  29. - ztsd public forum : https://groups.google.com/forum/#!forum/lz4c
  30. */
  31. #ifndef ZSTD_LEGACY_H
  32. #define ZSTD_LEGACY_H
  33. #if defined (__cplusplus)
  34. extern "C" {
  35. #endif
  36. /* *************************************
  37. * Includes
  38. ***************************************/
  39. #include "mem.h" /* MEM_STATIC */
  40. #include "error_private.h" /* ERROR */
  41. #include "zstd_v01.h"
  42. #include "zstd_v02.h"
  43. #include "zstd_v03.h"
  44. #include "zstd_v04.h"
  45. #include "zstd_v05.h"
  46. #include "zstd_v07.h"
  47. #include "zstd_v08.h"
  48. /** ZSTD_isLegacy() :
  49. @return : > 0 if supported by legacy decoder. 0 otherwise.
  50. return value is the version.
  51. */
  52. MEM_STATIC unsigned ZSTD_isLegacy (U32 magicNumberLE)
  53. {
  54. switch(magicNumberLE)
  55. {
  56. case ZSTDv01_magicNumberLE:return 1;
  57. case ZSTDv02_magicNumber : return 2;
  58. case ZSTDv03_magicNumber : return 3;
  59. case ZSTDv04_magicNumber : return 4;
  60. case ZSTDv05_MAGICNUMBER : return 5;
  61. case ZSTDv07_MAGICNUMBER : return 7;
  62. case ZSTDv08_MAGICNUMBER : return 8;
  63. default : return 0;
  64. }
  65. }
  66. MEM_STATIC size_t ZSTD_decompressLegacy(
  67. void* dst, size_t dstCapacity,
  68. const void* src, size_t compressedSize,
  69. const void* dict,size_t dictSize,
  70. U32 magicNumberLE)
  71. {
  72. switch(magicNumberLE)
  73. {
  74. case ZSTDv01_magicNumberLE :
  75. return ZSTDv01_decompress(dst, dstCapacity, src, compressedSize);
  76. case ZSTDv02_magicNumber :
  77. return ZSTDv02_decompress(dst, dstCapacity, src, compressedSize);
  78. case ZSTDv03_magicNumber :
  79. return ZSTDv03_decompress(dst, dstCapacity, src, compressedSize);
  80. case ZSTDv04_magicNumber :
  81. return ZSTDv04_decompress(dst, dstCapacity, src, compressedSize);
  82. case ZSTDv05_MAGICNUMBER :
  83. {
  84. size_t result;
  85. ZSTDv05_DCtx* zd = ZSTDv05_createDCtx();
  86. if (zd==NULL) return ERROR(memory_allocation);
  87. result = ZSTDv05_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
  88. ZSTDv05_freeDCtx(zd);
  89. return result;
  90. }
  91. case ZSTDv07_MAGICNUMBER :
  92. { size_t result;
  93. ZSTDv07_DCtx* const zd = ZSTDv07_createDCtx();
  94. if (zd==NULL) return ERROR(memory_allocation);
  95. result = ZSTDv07_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
  96. ZSTDv07_freeDCtx(zd);
  97. return result;
  98. }
  99. case ZSTDv08_MAGICNUMBER :
  100. { size_t result;
  101. ZSTDv08_DCtx* const zd = ZSTDv08_createDCtx();
  102. if (zd==NULL) return ERROR(memory_allocation);
  103. result = ZSTDv08_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
  104. ZSTDv08_freeDCtx(zd);
  105. return result;
  106. }
  107. default :
  108. return ERROR(prefix_unknown);
  109. }
  110. }
  111. #if defined (__cplusplus)
  112. }
  113. #endif
  114. #endif /* ZSTD_LEGACY_H */