Hello,
I have problem with appending dato into QByteArray from another QByteArray.
What I want to do is do decompress file, zlib, but in my Decompress() function I can only decompress as much as bufferSize (int) data, so I need to divide my compressed size into smaller chunks, not greater then bufferSize.
I do this as fallows, and I know that probably I should use QDataStram, but for the simplicity sake I use QByteArray.
while( !ba.isEmpty() ){
if( ba.size() <= 262144 ){
ba.remove( 0, ba.size() );
}else{
ba.remove( 0, 262144 );
}
baUncompre.append( Decompress( tmp ) );
}
while( !ba.isEmpty() ){
QByteArray tmp = ba.left( 262144 );
if( ba.size() <= 262144 ){
ba.remove( 0, ba.size() );
}else{
ba.remove( 0, 262144 );
}
baUncompre.append( Decompress( tmp ) );
}
To copy to clipboard, switch view to plain text mode
Then I write baUncompre to hdd.
The problem is that baUncompre have wrong size. I know that Decompress() works fine.
I tried baUncompre .resize( (int)uncompressedSize ); but that resize QBA not to the unompressed size but uncompressedSize +some more.
Can someone shed some light where is error in my thinking.
Best regards.
EDIT: I checked and loop is fine, error is that append appends more then decompressed size or lees (depends if I resize baUncompre or not).
EDIT: Sorry for garbage post, error was in Decompress() function.
Bookmarks