KBzip2Filter::Result KBzip2Filter::uncompress() { //qDebug() << "Calling bzDecompress with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable(); int result = bzDecompress(&d->zStream); if (result < BZ_OK) { qWarning() << "bzDecompress returned" << result; } switch (result) { case BZ_OK: return KFilterBase::Ok; case BZ_STREAM_END: return KFilterBase::End; default: return KFilterBase::Error; } }
KBzip2Filter::Result KBzip2Filter::uncompress() { //kdDebug(7118) << "Calling bzDecompress with avail_in=" << inBufferAvailable() << " avail_out=" << outBufferAvailable() << endl; int result = bzDecompress(&d->zStream); if ( result != BZ_OK ) { kdDebug(7118) << "bzDecompress returned " << result << endl; kdDebug(7118) << "KBzip2Filter::uncompress " << ( result == BZ_OK ? OK : ( result == BZ_STREAM_END ? END : ERROR ) ) << endl; } switch (result) { case BZ_OK: return OK; case BZ_STREAM_END: return END; default: return ERROR; } }
char Uncompressor::Uncompress(Input *input,unsigned char *dataptr,unsigned long *len) // Decompresses the data from 'input' and stores // the result in 'dataptr'. It decompresses at most *len // bytes. Afterwards, '*len' is set to the actual number // of bytes uncompressed. // The function returns 1, if output buffer is full and // there is more data to read. Otherwise, the function returns 0. { // We haven't initialized the object yet, we do that now if(isinitialized==0) { #ifdef USE_BZIP state.bzalloc=zalloc; state.bzfree=zfree; #else state.zalloc=zalloc; state.zfree=zfree; #endif #ifdef USE_BZIP if(bzDecompressInit(&state,0,0)!=BZ_OK) #else if(inflateInit(&state)!=Z_OK) #endif { Error("Error while compressing container!"); Exit(); } isinitialized=1; } int save_in; #ifdef USE_BZIP state.next_out=(char *)dataptr; #else state.next_out=(unsigned char *)dataptr; #endif // Let's remember how much space we have in the output ... state.avail_out=*len; // ... and we get the piece of data from the input state.avail_in=input->GetCurBlockPtr((char **)&(state.next_in)); do { // We save the amount of input data that is available // This will be used to compute how much input data was // decompressed save_in=state.avail_in; // The actual decompression #ifdef USE_BZIP switch(bzDecompress(&state)) #else switch(inflate(&state,Z_NO_FLUSH)) #endif { // Did we finish completely? #ifdef USE_BZIP case BZ_STREAM_END: #else case Z_STREAM_END: #endif // We skip over the amount of data that was decompressed input->SkipData(save_in-state.avail_in); // Let's store the overall amount of "decompressed" data. *len=state.total_out; // Let's finish the decompression entirely #ifdef USE_BZIP if(bzDecompressEnd(&state)!=BZ_OK) #else if(inflateReset(&state)!=Z_OK) #endif { Error("Error while compressing container!"); Exit(); } #ifdef USE_BZIP // Only for BZIP, we need to reinitialize isinitialized=0; #endif return 0; // We reached the end #ifdef USE_BZIP case BZ_OK: #else case Z_OK: #endif // Did we do the decompression correctly? // => Let's go to the next piece of data break; default: // In all other cases, we have an error Error("Error while uncompressing container!"); Exit(); } // Skip the input data that was decompressed input->SkipData(save_in-state.avail_in); if(state.avail_out==0) // Output buffer is full return 1; // if(state.avail_in>0) // Something is wrong ! // return -1; // Let's get the next input data block input->RefillAndGetCurBlockPtr((char **)&(state.next_in),(int *)&(state.avail_in)); } while(1); }