29 #define LZMA_API_STATIC
43 memlimit = lzma_easy_decoder_memusage(
level | LZMA_PRESET_EXTREME);
85 char *
buf = (
char *)calloc(1, 1024);
87 unsigned long chunklen;
88 unsigned long len = 0;
89 while((chunklen =
getChars(chunk, 1023))) {
90 memcpy(chunkbuf, chunk, chunklen);
94 else buf = (
char *)
realloc(buf, len + 1024);
98 zlen = (long)lzma_stream_buffer_bound(len);
104 switch (lzma_easy_buffer_encode(
level | LZMA_PRESET_EXTREME, LZMA_CHECK_CRC64,
NULL, (
const uint8_t*)
buf, (size_t)len, (uint8_t*)
zbuf, &
zpos, (size_t)
zlen)) {
105 case LZMA_OK:
sendChars(zbuf, zpos);
break;
106 case LZMA_BUF_ERROR: fprintf(stderr,
"ERROR: not enough room in the out buffer during compression.\n");
break;
107 case LZMA_UNSUPPORTED_CHECK: fprintf(stderr,
"ERROR: unsupported_check error encountered during decompression.\n");
break;
108 case LZMA_OPTIONS_ERROR: fprintf(stderr,
"ERROR: options error encountered during decompression.\n");
break;
109 case LZMA_MEM_ERROR: fprintf(stderr,
"ERROR: not enough memory during compression.\n");
break;
110 case LZMA_DATA_ERROR: fprintf(stderr,
"ERROR: corrupt data during compression.\n");
break;
111 case LZMA_PROG_ERROR: fprintf(stderr,
"ERROR: program error encountered during decompression.\n");
break;
112 default: fprintf(stderr,
"ERROR: an unknown error occurred during compression.\n");
break;
116 fprintf(stderr,
"ERROR: no buffer to compress\n");
136 char *
zbuf = (
char *)calloc(1, 1024);
137 char *chunkbuf =
zbuf;
139 unsigned long zlen = 0;
140 while((chunklen =
getChars(chunk, 1023))) {
141 memcpy(chunkbuf, chunk, chunklen);
145 else zbuf = (
char *)
realloc(zbuf, zlen + 1024);
146 chunkbuf = zbuf +
zlen;
151 unsigned long blen = zlen*20;
152 char *
buf =
new char[blen];
158 switch (lzma_stream_buffer_decode((uint64_t *)&
memlimit, 0,
NULL, (
const uint8_t*)zbuf, &zpos, (
size_t)zlen, (uint8_t*)buf, &bpos, (
size_t)&blen)){
160 case LZMA_FORMAT_ERROR: fprintf(stderr,
"ERROR: format error encountered during decompression.\n");
break;
161 case LZMA_OPTIONS_ERROR: fprintf(stderr,
"ERROR: options error encountered during decompression.\n");
break;
162 case LZMA_DATA_ERROR: fprintf(stderr,
"ERROR: corrupt data during decompression.\n");
break;
163 case LZMA_NO_CHECK: fprintf(stderr,
"ERROR: no_check error encountered during decompression.\n");
break;
164 case LZMA_UNSUPPORTED_CHECK: fprintf(stderr,
"ERROR: unsupported_check error encountered during decompression.\n");
break;
165 case LZMA_MEMLIMIT_ERROR: fprintf(stderr,
"ERROR: memlimit error encountered during decompression.\n");
break;
166 case LZMA_MEM_ERROR: fprintf(stderr,
"ERROR: not enough memory during decompression.\n");
break;
167 case LZMA_BUF_ERROR: fprintf(stderr,
"ERROR: not enough room in the out buffer during decompression.\n");
break;
168 case LZMA_PROG_ERROR: fprintf(stderr,
"ERROR: program error encountered during decompression.\n");
break;
169 default: fprintf(stderr,
"ERROR: an unknown error occurred during decompression.\n");
break;
174 fprintf(stderr,
"ERROR: no buffer to decompress!\n");
193 memlimit = lzma_easy_decoder_memusage(
level | LZMA_PRESET_EXTREME);
#define SWORD_NAMESPACE_START
virtual void encode(void)
virtual void setLevel(int l)
virtual unsigned long getChars(char *buf, unsigned long len)
virtual void decode(void)
#define SWORD_NAMESPACE_END
virtual unsigned long sendChars(char *buf, unsigned long len)