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