LzmaLib.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* LzmaLib.c -- LZMA library wrapper
  2. 2015-06-13 : Igor Pavlov : Public domain */
  3. #include "Alloc.h"
  4. #include "LzmaDec.h"
  5. #include "LzmaEnc.h"
  6. #include "LzmaLib.h"
  7. MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
  8. unsigned char *outProps, size_t *outPropsSize,
  9. int level, /* 0 <= level <= 9, default = 5 */
  10. unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */
  11. int lc, /* 0 <= lc <= 8, default = 3 */
  12. int lp, /* 0 <= lp <= 4, default = 0 */
  13. int pb, /* 0 <= pb <= 4, default = 2 */
  14. int fb, /* 5 <= fb <= 273, default = 32 */
  15. int numThreads /* 1 or 2, default = 2 */
  16. )
  17. {
  18. CLzmaEncProps props;
  19. LzmaEncProps_Init(&props);
  20. props.level = level;
  21. props.dictSize = dictSize;
  22. props.lc = lc;
  23. props.lp = lp;
  24. props.pb = pb;
  25. props.fb = fb;
  26. props.numThreads = numThreads;
  27. return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,
  28. NULL, &g_Alloc, &g_Alloc);
  29. }
  30. MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,
  31. const unsigned char *props, size_t propsSize)
  32. {
  33. ELzmaStatus status;
  34. return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);
  35. }