我只想说zlib libzip不是同一个库。

先安装zlib,再安装 libzip,不然libglib始终安装不成功。

sudo apt-get install zlib1g-dev

下载:zlib-1.2.11.tar.gz
     tar zxcv zlib-1.2.11.tar.gz 
    cd zlib-1.2.11 
   ./configure; make; make install

下载:libzip-1.0.1.tar.gz
tar zxcv libzip-1.0.1.tar.gz
cd libzip-1.0.1
./configure; make; make install

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"  #设置路径
sudo echo $PKG_CONFIG_PATH #查看路径

安装成功后可以看到*.pc文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
zlib是提供数据压缩用的函式,由Jean-loup Gailly与Mark Adler所开发,初版0.9版在1995年5月1日发表。zlib使用DEFLATE算法,最初是为libpng函式所写的,后来普遍为许多软件所使用。此函式为自由软件,使用zlib授权。截至2007年3月,zlib是包含在Coverity的美国国土安全部赞助者选择继续审查的开源项目。 qlibzip 是基于zlib的一个实用程序,使用Qt和Windows一些底层API实现,它主要用于将文件夹压缩到一个zip文件,或将一个zip文件解压缩到文件夹。 //------------------------------------------------------------------------------ // Description: Compress files to a ZIP file. // Parameter: sourceFiles Source files, supporting wildcards. // Parameter: destFile The ZIP file path. // Return Value: true/false. //------------------------------------------------------------------------------ extern "C" bool ZipCompress(const QString &sourceFiles, const QString &destFile); //------------------------------------------------------------------------------ // Description: Extract files from a ZIP file. // Parameter: sourceFile Source ZIP file. // Parameter: destFolder The folder to output files. The parent of the // specified folder MUST exist. // Return Value: true/false. //------------------------------------------------------------------------------ extern "C" bool ZipExtract(const QString &sourceFile, const QString &destFolder); //------------------------------------------------------------------------------ // Description: Extract special file from a ZIP file into memory block. // Parameter: sourceFile Source ZIP file. // Parameter: entryName Special entry name in ZIP file. // Return Value: Extracted memory block. //------------------------------------------------------------------------------ extern "C" QByteArray ZipExtractItem(const QString &sourceFile, const QString &entryName); 具体实例请看demo文件夹。
要获取压缩包中压缩包的名字,我们需要使用zlib提供的函数来解压缩文件,并且读取其中的目录信息。以下是一个简单的C语言程序,可以实现这个功能: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #include "zlib.h" #define CHUNK_SIZE 16384 int main(int argc, char *argv[]) { gzFile file = NULL; char buf[CHUNK_SIZE]; int len = 0, pos = 0, i = 0; unsigned char header[10]; unsigned long filesize = 0, uncompressed_size = 0; if (argc < 2) { printf("Usage: %s <filename>\n", argv[0]); return 1; } file = gzopen(argv[1], "rb"); if (!file) { printf("Error: Failed to open file '%s'\n", argv[1]); return 1; } // read gzip header len = gzread(file, header, 10); if (len != 10 || memcmp(header, "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff", 10)) { printf("Error: %s is not a valid gzip file.\n", argv[1]); gzclose(file); return 1; } // read file name and extra fields while (1) { len = gzread(file, buf, CHUNK_SIZE); if (len == 0) { printf("Error: Failed to read file name and extra fields.\n"); gzclose(file); return 1; } for (i = 0; i < len; i++) { if (buf[i] == 0) { pos = i + 1; break; } } if (pos > 0) { break; } } // read file size memcpy(&filesize, buf + pos, sizeof(unsigned long)); pos += sizeof(unsigned long); // read uncompressed size memcpy(&uncompressed_size, buf + pos, sizeof(unsigned long)); pos += sizeof(unsigned long); // read file name printf("The compressed file name is: %s\n", buf + pos); gzclose(file); return 0; } ``` 这个程序打开了一个gzip文件,并且读取了其中的文件名和额外的字段。它也解析了文件的大小和未压缩大小,但是这些信息对于我们需要的压缩包名字并没有用处。最终,程序输出了压缩包名字,并且关闭了文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值