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