Hi I am programming a wrapper class of BZ2 library here is some code first for decompressing
Code:
        if(!ValidFileHandles())
		return -1;
	if(!DetermineInSize())
		return -1;

	char inBuf[BUFF_S],outBuf[BUFF_S];
	bz_stream str;
	int er=0;
	unsigned int bRead=bytes;

	str.bzalloc=NULL;
	str.bzfree =NULL;
	str.opaque =NULL;

	str.next_in=inBuf;
	str.next_out=outBuf;
	str.avail_in=BUFF_S;
	str.avail_out=BUFF_S;

	er=BZ2_bzDecompressInit(&str,0,Small);
	
	if(er!=BZ_OK)
	{
		return er;
	}

	str.avail_in=0;
	fseek(in,offset,SEEK_SET);
	do
	{
		if(str.avail_in==0)
		{
			if(bRead>=BUFF_S)
			{
				str.avail_in=fread(inBuf,1,BUFF_S,in);
				bRead-=BUFF_S;
			}
			else if(bRead!=0)
			{
				str.avail_in=fread(inBuf,1,bRead,in);
				bRead=0;
			}else
				str.avail_in=0;
			str.next_in=inBuf;
		}

		er=BZ2_bzDecompress(&str);

		if(er==BZ_OK)
		{
			//getchar();
		}
		else if(er!=BZ_STREAM_END)
		{
			fflush(out);
			BZ2_bzDecompressEnd(&str);
			return er;
		}

		ptr(str.total_in_lo32,str.total_out_hi32,bytes);

		if(str.avail_out!=BUFF_S)
		{
			fwrite(outBuf,1,BUFF_S-str.avail_out,out);
			str.next_out=outBuf;
			str.avail_out=BUFF_S;
		}

	}while(er!=BZ_STREAM_END);

	fflush(out);

	er=BZ2_bzDecompressEnd(&str);
	if(str.avail_out!=BUFF_S)
	{
		fwrite(outBuf,1,BUFF_S-str.avail_out,out);
		ptr(str.total_in_lo32,str.total_out_lo32,bytes);
		fflush(out);
	}

	return er;
Here BUFF_S is 5120 and bytes are total number of bytes to be read from file and the offset is the offset in file where to start from....


Problem is the loop never ends although I have provided data with correctly compressed with BZ2_bzCompress and using all the method the manual says.
And it returns success but BZ2_bzDecompress never returns BZ_STREAM_END.

Whats problem...