66 char *
buf = (
char *)calloc(1, 1024);
68 unsigned long chunklen;
69 unsigned long len = 0;
70 while((chunklen =
getChars(chunk, 1023))) {
71 memcpy(chunkbuf, chunk, chunklen);
75 else buf = (
char *)
realloc(buf, len + 1024);
80 zlen = (long) (len*1.01)+600;
85 if (BZ2_bzBuffToBuffCompress(zbuf, (
unsigned int*)&
zlen,
buf, (
unsigned int)len,
level, 0, 0) != BZ_OK)
87 printf(
"ERROR in compression\n");
95 fprintf(stderr,
"ERROR: no buffer to compress\n");
115 char *
zbuf = (
char *)calloc(1, 1024);
116 char *chunkbuf =
zbuf;
118 unsigned long zlen = 0;
119 while((chunklen = (
int)
getChars(chunk, 1023))) {
120 memcpy(chunkbuf, chunk, chunklen);
124 else zbuf = (
char *)
realloc(zbuf, zlen + 1024);
125 chunkbuf = zbuf +
zlen;
130 unsigned int blen = (
unsigned int)(zlen*20);
131 char *
buf =
new char[blen];
134 switch (BZ2_bzBuffToBuffDecompress(buf, &blen, zbuf, (
unsigned int)
zlen, 0, 0)){
136 case BZ_MEM_ERROR: fprintf(stderr,
"ERROR: not enough memory during decompression.\n");
break;
137 case BZ_OUTBUFF_FULL: fprintf(stderr,
"ERROR: not enough room in the out buffer during decompression.\n");
break;
138 case BZ_DATA_ERROR: fprintf(stderr,
"ERROR: corrupt data during decompression.\n");
break;
139 default: fprintf(stderr,
"ERROR: an unknown error occurred during decompression.\n");
break;
144 fprintf(stderr,
"ERROR: no buffer to decompress!\n");
#define SWORD_NAMESPACE_START
virtual void decode(void)
virtual void encode(void)
virtual unsigned long getChars(char *buf, unsigned long len)
#define SWORD_NAMESPACE_END
virtual unsigned long sendChars(char *buf, unsigned long len)