I am attempting to read the bytes from one file, compress them, stick them in another file, and read that file back in at a later time to get those bytes. But the bytes I write don't seem to be the same bytes I read back in and they should be. I tried computing a checksum to verify but the problem I see is that checksumBefore does not equal checksumAfter (see below). What am I missing?
QList<QByteArray> _compressedArrayList;
QFile file1
( "foo.xml" );
file1.
open( QFile::ReadOnly );
QByteArray compressedFileBytes
= qCompress
( fileBytes
);
quint16 checksumBefore = qChecksum( compressedFileBytes.data(), compressedFileBytes.count() );
_compressedArrayList << compressedFileBytes;
file1.close();
{
foreach
( QByteArray byteArray, _compressedArrayList
) {
fout << byteArray.data();
}
file.close();
}
//..............
//..............
QFile packageFile
( "out" );
packageFile.
open( QFile::ReadOnly );
QByteArray compressedFileBytes
= packageFile.
read( compressedFileBytes.
count() );
quint16 checksumAfter = qChecksum( compressedFileBytes.data(), compressedFileBytes.count() );
QList<QByteArray> _compressedArrayList;
QFile file1( "foo.xml" );
file1.open( QFile::ReadOnly );
QByteArray fileBytes = file1.readAll();
QByteArray compressedFileBytes = qCompress( fileBytes );
quint16 checksumBefore = qChecksum( compressedFileBytes.data(), compressedFileBytes.count() );
_compressedArrayList << compressedFileBytes;
file1.close();
QFile file( "out" );
if( file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
{
QDataStream fout( &file );
foreach( QByteArray byteArray, _compressedArrayList )
{
fout << byteArray.data();
}
file.close();
}
//..............
//..............
QFile packageFile( "out" );
packageFile.open( QFile::ReadOnly );
QByteArray compressedFileBytes = packageFile.read( compressedFileBytes.count() );
quint16 checksumAfter = qChecksum( compressedFileBytes.data(), compressedFileBytes.count() );
To copy to clipboard, switch view to plain text mode
Bookmarks