Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

use qUncompress to uncompress data compressed by zlib with another application



  • Hi,

    I have two applications. One is written in delphi, which is compressing data with zlib.
    The other one is written in c++ which should uncompress this data.

    In detail:
    In delphi I create a file compress it and add a 4 byte header to the compressed data:

      destStream := TFileStream.Create(SaveDialog1.FileName, fmCreate);
      destStream.WriteData(sourceStream.Size, 4);  // here I add the header for qUncompress
      sourceStream.Seek(0, soFromBeginning);
      LZip := TZCompressionStream.Create(clMax, destStream);
      LZip.CopyFrom(sourceStream, sourceStream.Size);
    

    In QT i try to uncompress this data like this:

        QFile file("E:\\Temp\\wheels\\test.adb");
        if (!file.open(QIODevice::ReadOnly))
            return;
    
        QByteArray compressed = file.readAll();
        qDebug() << "Compresed=" << compressed.size();
    
        QByteArray uncompressed = qUncompress(compressed); // HERE I GET: qUncompress: Input data is corrupted
        qDebug() << "UnCompresed=" << uncompressed.size();
    

    Any idea what I'm doing wrong?
    Unfortunately I haven't seen the source of qUncompress yet. So don't know what it is expecting.

    THX
    mts


  • Moderators

    @themts said:

    Unfortunately I haven't seen the source of qUncompress yet. So don't know what it is expecting.

    Here you go



  • Thanks, that already helped.
    I just forgot to swap endian.



  • KArchive is the best free code available to handle compressed files


Log in to reply