Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUncompress can't read a file which was compressed with qCompress
Forum Updated to NodeBB v4.3 + New Features

QUncompress can't read a file which was compressed with qCompress

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbertschi
    wrote on last edited by
    #1

    Alright, all I want to do is to compress and uncompress a file with qCompress/qUncompress:

    @QCoreApplication a(argc, argv);
    QStringList args = QCoreApplication::arguments();

    if(args.count() > 1){

    if(args.at(1) == "-d"){//Decompress
    QFile source(args.at(2));
    if(source.open(QFile::ReadOnly)){
    QByteArray compressedData = source.readAll();
    QByteArray deCompressedData = qUncompress(compressedData);
    source.close();
    QFileInfo info(source);
    QDir destinationDir(info.dir());
    QFileInfo destinationInfo(destinationDir, info.baseName());

    QFile destination(destinationInfo.absoluteFilePath());
    destination.open(QFile::WriteOnly);
    QTextStream destStream(&destination);
    destStream << deCompressedData;
    destStream.flush();
    destination.close();
    

    }
    }
    else{//Compress
    QFile source(args.at(1));
    if(source.open(QFile::ReadOnly)){
    QByteArray compressedData = qCompress(source.readAll());
    source.close();
    QFileInfo info(source);
    QDir destinationDir(info.dir());
    QFileInfo destinationInfo(destinationDir, info.fileName() + ".gz");

    QFile destination(destinationInfo.absoluteFilePath());
    destination.open(QFile::WriteOnly);
    QTextStream destStream(&destination);
    destStream << compressedData;
    destStream.flush();
    destination.close();
    

    }
    }
    }@

    Oddly, qUncompress gives me "qUncompress: Z_DATA_ERROR: Input Data is corrupted", eventhough the original data was compressed with qCompress?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved