计算机培训机构培训出来好就业吗,内蒙网站建设seo优化,网络营销型网站建设,现在清算组备案在哪个网站做bit7z一个c静态库#xff0c;为7-zip共享库提供了一个干净简单的接口 使用CMAKE重新编译github上的bit7z库#xff0c;用来解压/预览iso9660#xff0c;WIm#xff0c;Zip,Rar等常用的压缩文件格式。z-zip库支持大多数压缩文件格式 导读 编译bit7z(C版本)使用mscv 2017编译… bit7z一个c静态库为7-zip共享库提供了一个干净简单的接口 使用CMAKE重新编译github上的bit7z库用来解压/预览iso9660WImZip,Rar等常用的压缩文件格式。z-zip库支持大多数压缩文件格式 导读 编译bit7z(C版本)使用mscv 2017编译器编译参考借鉴文章 下载bit7z(QT版本)调用bit7z库调用库(hotfix/v3.1.4/示例)解压文件压缩文件查看文件详细 调用库可执行程序示例 编译bit7z(C版本)
bit7z是一个跨平台的c静态库它允许通过一个干净简单的包装器接口从7-zip项目压缩/提取归档文件到动态库。 它支持对文件系统或内存进行压缩和提取、读取存档元数据、更新现有的存档元数据、创建多卷存档、操作进度回调以及许多其他功能。 压缩支持格式7z, XZ, BZIP2, GZIP, TAR, ZIP, and WIM. 解压支持格式7z, AR, ARJ, BZIP2, CAB, CHM, CPIO, CramFS, DEB, DMG, EXT, FAT, GPT, GZIP, HFS, HXS, IHEX, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, QCOW2, RAR, RAR5, RPM, SquashFS, TAR, UDF, UEFI, VDI, VHD, VMDK, WIM, XAR, XZ, Z, and ZIP 更多详细https://github.com/rikyoz/bit7z 不建议使用此版本调用7-zip库
使用mscv 2017编译器编译
从https://github.com/rikyoz/bit7z下载源码后解压使用cMake默认mscv2017直接可以编译选项直接默认或者全选就行然后再点击 Configure-》generate; 编译后生成以下目录 此时需要返回bit7z-master原目录添加lamz1900包 下载lamz1900包https://www.7-zip.org/a/lzma1900.7z 解压lzma1900将lzma1900中的文件复制到bit7z-master包下的third_party/7-zip文件夹中 打开编译好的bit7z.sln文件修改设置bit7z为启动项修改属性页-》c/C附件目录中的库文件目录然后右键重新生成在生成目录下找到生成好的bit7z.lib文件 通过这种方法生成lib库BitCompressor 类变成了一个模版类调用方式参考github的后半段说明比较繁琐源码中展示的案例也貌似是付费内容需要三方库。 建议直接通过编译下载Qt版本bit7z库调用
参考借鉴文章
C 7z解压缩编译及使用 c配置并使用bit7z加密压缩或解压7z文件 bit7z库 https://github.com/rikyoz/bit7z
下载bit7z(QT版本)
直接下载Qt版本的bit7z库能直接重新选择编译器生成Bit7z库 主要是参考这篇文章 qt5 7zip源码编译及使用(含展示进度) 解压后直接可以打开bit7z.pro 同时也需要把lzma1900中的文件放到7zsdk文件夹中再选择编译器编译就行。
调用bit7z库
以Qt版本源码生成的bit7z库为例需要在项目pro文件中添加lib引用和include文件夹引用
///生成的lib库地址
win32:CONFIG(release, debug|release): LIBS -L$$DESTDIR/ -lbit7z
else:win32:CONFIG(debug, debug|release): LIBS -L$$DESTDIR/ -lbit7zd#include文件目录所在 包括所有hpp头文件
INCLUDEPATH $$PWD/../bit7z
DEPENDPATH $$PWD/../bit7z注意调用时需要OleAut32.lib和User32.lib这两个文件
# 不加上-lOleAut32 -lUser32这段 bit7z无法解析
LIBS -L$$DESTDIR -lbit7z -lOleAut32 -lUser32编译时最好在bitformat.hpp文件中添加此宏定义
//使用此宏定义调用时只需要使用 BitFormat::Auto
//不用再判断文件类型
#define BIT7Z_AUTO_FORMAT和bit7z.lib文件放在同一目录下。 参考 qt5 7zip源码编译及使用(含展示进度) https://gitcode.net/mirrors/rikyoz/Bit7z/-/tree/hotfix/v3.1.4
至于需要的7-zip库 7z.dll可以通过官网7-Zip -程序下载安装后获取。 7za.dll和7zxa.dll可以直接下载https://www.7-zip.org/a/7z1900-extra.7z解压获取 建议7za.dll和7zxa.dll和7z.dll和执行程序放同一目录下 其中 7z.dll应该支持所有功能而7za.dll应该只支持7z文件格式而7zxa.dll只能提取7z文件
the 7z.dll should support all these features, while 7za.dll should support only the 7z file format and the 7zxa.dll can only extract 7z files. For more information about the 7-zip DLLs, please see this wiki page
编译出现异常可以参考[笔记] 编译bit7z踩坑记录
调用库(hotfix/v3.1.4/示例)
解压文件
#include bitextractor.hppusing namespace bit7z;try {Bit7zLibrary lib{ L7za.dll };//启用宏定义BIT7Z_AUTO_FORMAT后可以直接使用BitFormat::AutoBitExtractor extractor{ lib, BitFormat::SevenZip };extractor.extract( Lpath/to/archive.7z, Lout/dir/ ); //extracting a simple archiveextractor.extractMatching( Lpath/to/arc.7z, Lfile.pdf, Lout/dir/ ); //extracting a specific file//extracting the first file of an archive to a bufferstd::vector byte_t buffer;extractor.extract( Lpath/to/archive.7z, buffer );//extracting an encrypted archiveextractor.setPassword( Lpassword );extractor.extract( Lpath/to/another/archive.7z, Lout/dir/ );
} catch ( const BitException ex ) {//do something with ex.what()...
}
压缩文件
#include bitcompressor.hppusing namespace bit7z;try {Bit7zLibrary lib{ L7z.dll };//启用宏定义BIT7Z_AUTO_FORMAT后可以直接使用BitFormat::AutoBitCompressor compressor{ lib, BitFormat::Zip };std::vector std::wstring files { Lpath/to/file1.jpg, Lpath/to/file2.pdf };compressor.compress( files, Loutput_archive.zip ); //creating a simple zip archive//creating a zip archive with a custom directory structurestd::map std::wstring, std::wstring files_map { { Lpath/to/file1.jpg, Lalias/path/file1.jpg },{ Lpath/to/file2.pdf, Lalias/path/file2.pdf } };compressor.compress( files_map, Loutput_archive2.zip );compressor.compressDirectory( Ldir/path/, Ldir_archive.zip ); //compressing a directory//creating an encrypted zip archive of two filescompressor.setPassword( Lpassword );compressor.compressFiles( files, Lprotected_archive.zip );//updating an existing zip archivecompressor.setUpdateMode( true );compressor.compressFiles( files, Lexisting_archive.zip );//compressing a single file into a bufferstd::vector byte_t buffer;BitCompressor compressor2{ lib, BitFormat::BZip2 };compressor2.compressFile( files[0], buffer );
} catch ( const BitException ex ) {//do something with ex.what()...
}
查看文件详细
可以通过此方法直接预览压缩文件夹内容
#include bitarchiveinfo.hppusing namespace bit7z;try {Bit7zLibrary lib{ L7za.dll };BitArchiveInfo arc{ lib, Larchive.7z, BitFormat::SevenZip };//printing archive metadatawcout LArchive properties endl;wcout L Items count: arc.itemsCount() endl;wcout L Folders count: arc.foldersCount() endl;wcout L Files count: arc.filesCount() endl;wcout L Size: arc.size() endl;wcout L Packed size: arc.packSize() endl;wcout endl;//printing archive items metadatawcout LArchive items;auto arc_items arc.items();for ( auto item : arc_items ) {wcout endl;wcout L Item index: item.index() endl;wcout L Name: item.name() endl;wcout L Extension: item.extension() endl;wcout L Path: item.path() endl;wcout L IsDir: item.isDir() endl;wcout L Size: item.size() endl;wcout L Packed size: item.packSize() endl;}
} catch ( const BitException ex ) {//do something with ex.what()...
}
调用库可执行程序示例
Qt调用Bit7z库接口调用7z.dll解压压缩常用Zip、ISO9660、Wim、7z等格式的可执行程序非源码Qt案例