1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
char *compressBuffer_BZ2(char *src,unsigned long srcl,unsigned long *dstl){
unsigned long l=srcl,realsize=l;
char *dst=new char[l];
while (BZ2_bzBuffToBuffCompress(dst,(unsigned int *)&l,src,srcl,1,0,0)==BZ_OUTBUFF_FULL){
delete[] dst;
l*=2;
realsize=l;
dst=new char[l];
}
if (l!=realsize){
char *temp=new char[l];
memcpy(temp,dst,l);
delete[] dst;
dst=temp;
}
*dstl=l;
return dst;
}
char *decompressBuffer_BZ2(char *src,unsigned long srcl,unsigned long *dstl){
unsigned long l=srcl,realsize=l;
char *dst=new char[l];
while (BZ2_bzBuffToBuffDecompress(dst,(unsigned int *)&l,src,srcl,1,0)==BZ_OUTBUFF_FULL){
delete[] dst;
l*=2;
realsize=l;
dst=new char[l];
}
if (l!=realsize){
char *temp=new char[l];
memcpy(temp,dst,l);
delete[] dst;
dst=temp;
}
*dstl=l;
return dst;
}
| |