LzmaLib.c 1.5 KB

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