main()
{
char source[1560]="mrinalsaikiaismynamenwhatnotiamgreatajajlksjkkslskldklkdklkdlwhgygehehhejhjejdjjjjjljlkkjjjjjjaasasaaasjsjssjskjkjalsjalksjajslkjckljdjfjfjfjffjkllkjldkjlskjlkjkljklklkalksklksjkjskjksjlksjjskjklsjsjskjkjkjjjsjkjjjjjbhbjbbjbjbssjbsjsbsjssjssjhjdjdjjkkmrinalsaikiaismynamenwhatnotiamgreatajajlksjkkslskldklkdklkdlwhgygehehhejhjejdjjjjjljlkkjjjjjjaasasaaasjsjssjskjkjalsjalksjajslkjckljdjfjfjfjffjkllkjldkjlskjlkjkljklklkalksklksjkjskjksjlksjjskjklsjsjskjkjkjjjsjkjjjjjbhbjbbjbjbssjbsjsbsjssjssjhjdjdjjkk";
int ret ;
bz_stream comp_stream;
comp_stream.next_in = source;
comp_stream.avail_in =strlen(source);
comp_stream.avail_out = 502 ;
char arr[comp_stream.avail_out];
comp_stream.next_out =arr;
comp_stream.opaque = NULL;
comp_stream.bzfree = NULL;
comp_stream.bzalloc = NULL;
comp_stream.state = NULL;
BZ2_bzCompressInit(&comp_stream,1,0,0);
printf("length before compression = %d \n",strlen(source));
printf(" string original is %s \n",(comp_stream.next_in));
if(BZ2_bzCompress(&comp_stream, BZ_FINISH) == BZ_STREAM_END)
{
printf("copressed Data\n");
printf("compressed size length = %d \n",(502 - comp_stream.avail_out));
}
printf("compressed string = %s \n",comp_stream.next_out);
Decompress(comp_stream.next_out,(502 - comp_stream.avail_out));
BZ2_bzCompressEnd(&comp_stream);
Asked
Active
Viewed 75 times
0

ForceBru
- 43,482
- 10
- 63
- 98

salman khan
- 33
- 6
-
1What's the question? Do you get an output different from what you expected? If so, please state your expected output and the one you actually get – bznein Oct 19 '15 at 14:26
-
ya i am geting output but i don't know it's right or wrong but when i am decompress that string that will give me BZ_DATA_ERROR_MAGIC error. – salman khan Oct 19 '15 at 14:28
-
You have been a member here on SO long enough to have read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). You should also have had time to [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask). – Some programmer dude Oct 19 '15 at 14:32
-
sorry deimus i written this code in hurry can you explain me how to do compress using bzip2 low level api.... – salman khan Oct 19 '15 at 14:33
1 Answers
0
The value of next_out
will change if any data was written, just like next_in
will change if any data was read. In other words, you're trying to decompress the data from immediately after your compressed data ends.

nemequ
- 16,623
- 1
- 43
- 62
-
(thanks for reply) ...yes but what is the problem in that... i want to check it properly compressed or not .. – salman khan Oct 20 '15 at 04:30
-
Decompression requires a pointer to the *beginning* of the decompressed data, not a pointer to the byte *after* the decompressed data ends. – nemequ Oct 20 '15 at 16:27
-
comp_stream.next_out is point to decompress string which is point to beginning of decompressed data.... – salman khan Oct 23 '15 at 04:38