简体   繁体   English

无法打开压缩文件

[英]Can't open compressed file

I'm trying to compress a text file with QT: 我正在尝试使用QT压缩文本文件:

QFile inFile("d:\\build\\Directories\\Debug\\files\\developer.txt");
bool open_file_result = inFile.open(QIODevice::ReadOnly);
QByteArray ba = inFile.readAll();

QFile file("d:\\build\\Directories\\Debug\\files\\developer.gz");
bool open_zip_result = file.open(QIODevice::WriteOnly);
QDataStream out(&file);
out << qCompress(ba);

file.close();

open_file_result and open_zip_result are both true . open_file_resultopen_zip_result均为true I can also see the zip file (it also has a size, such as 50KB) but I can't open it. 我还可以看到zip文件(它也有一个大小,例如50KB),但我无法打开它。 I'm getting the following error: 我收到以下错误:

The archive is either in unknown format or damaged. 归档文件格式未知或已损坏。

What am I doing wrong? 我究竟做错了什么? If you have a better/another way to compress a text file, please tell me! 如果您有更好/另一种方式来压缩文本文件,请告诉我!

There is a difference between the Zip compression algorithm and the Zip container. Zip压缩算法和Zip容器之间存在差异。 You're confusing the two. 您混淆了两者。

You need to do some research into the Zip container format that will help you locate and extract a zipped file within a Zip container. 您需要对Zip容器格式进行一些研究,以帮助您在Zip容器中查找和提取压缩文件。 Once you've gotten that file, you can apply qUncompress to that file only. 获得该文件后,您只能将qUncompress应用于该文件。

Try looking at the QuaZip , which is a library that has been written for this purpose. 尝试查看QuaZip ,这是为此目的而编写的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM