nuclear@14: /* LzmaLib.c -- LZMA library wrapper nuclear@14: 2008-08-05 nuclear@14: Igor Pavlov nuclear@14: Public domain */ nuclear@14: nuclear@14: #include "LzmaEnc.h" nuclear@14: #include "LzmaDec.h" nuclear@14: #include "Alloc.h" nuclear@14: #include "LzmaLib.h" nuclear@14: nuclear@14: static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } nuclear@14: static void SzFree(void *p, void *address) { p = p; MyFree(address); } nuclear@14: static ISzAlloc g_Alloc = { SzAlloc, SzFree }; nuclear@14: nuclear@14: MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, nuclear@14: unsigned char *outProps, size_t *outPropsSize, nuclear@14: int level, /* 0 <= level <= 9, default = 5 */ nuclear@14: unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */ nuclear@14: int lc, /* 0 <= lc <= 8, default = 3 */ nuclear@14: int lp, /* 0 <= lp <= 4, default = 0 */ nuclear@14: int pb, /* 0 <= pb <= 4, default = 2 */ nuclear@14: int fb, /* 5 <= fb <= 273, default = 32 */ nuclear@14: int numThreads, /* 1 or 2, default = 2 */ nuclear@14: int algo /* 0 = fast, 1 = normal */ nuclear@14: ) nuclear@14: { nuclear@14: CLzmaEncProps props; nuclear@14: LzmaEncProps_Init(&props); nuclear@14: props.level = level; nuclear@14: props.dictSize = dictSize; nuclear@14: props.lc = lc; nuclear@14: props.lp = lp; nuclear@14: props.pb = pb; nuclear@14: props.fb = fb; nuclear@14: props.numThreads = numThreads; nuclear@14: props.algo = algo; nuclear@14: nuclear@14: return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0, nuclear@14: NULL, &g_Alloc, &g_Alloc); nuclear@14: } nuclear@14: nuclear@14: nuclear@14: MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen, nuclear@14: const unsigned char *props, size_t propsSize) nuclear@14: { nuclear@14: ELzmaStatus status; nuclear@14: return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc); nuclear@14: }