[笔记] 编译bit7z踩坑记录

简介: [笔记] 编译bit7z踩坑记录

前言

最近在使用解压各种格式文件,做进一步内容检测,发现docx是zip格式,doc是ole格式,zip格式可以用zlib库解压,ole却不行,发现7z可以解压,于是便有了一系列的操作。

步骤

bit7z 是一个开源项目,在7z的基础上做了一层封装,依赖7z的库,所以编译使用过程需要加入7z的DLL,和头文件等。

简单编译bit7z描述整个过程:

  1. 拉去bit7z代码
  2. 下载7z sdk
  3. 7z sdk解压放到到bit7z项目的third_part目录7-Zip
  4. 7z sdk解压再放到bit7z项目的include目录
  5. 下载7z sdk extra补充包 解压其中7za.dll 或者 7z.dll(根据自己的需求确认)
  6. 按照官网文档使用cmake构建和编译:
cd <bit7z folder>
mkdir build && cd build
cmake ../ -DCMAKE_BUILD_TYPE=Release
cmake --build . -j --config Release

注意:

7za.dll 只支持7z格式的解压和压缩

7z.dll 支持大多数格式的解压和压缩。

解压测试

注意:BitFormat::Auto 选项需要编译bit7z时,添加 BIT7Z_AUTO_FORMAT

// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
/*
 * bit7z - A C++ static library to interface with the 7-zip shared libraries.
 * Copyright (c) 2014-2022 Riccardo Ostani - All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */
 //#define BIT7Z_USE_NATIVE_STRING
#define BIT7Z_AUTO_FORMAT
#include <bitexception.hpp>
//#include <bitarchiveinfo.hpp>
#include <bit7zlibrary.hpp>
#include <bitarchivereader.hpp>
#include <bitfileextractor.hpp>
#include <iostream>
//#pragma comment(lib, "D:\\workspace\\github\\bit7z\\lib\\x64\\Release\\bit7z64.lib")
using namespace std;
using namespace bit7z;
int main(int argc, char* argv[]) {
    try { // bit7z classes can throw BitException objects
        using namespace bit7z;
        Bit7zLibrary lib{ "D:\\workspace\\github\\bit7z\\bin\\x64\\Debug\\7z.dll" };
        BitFileExtractor extractor{ lib, BitFormat::Auto };
        // Extracting a simple archive
        extractor.extract("D:\\test_office.doc", "D:\\test_office\\");
        // Extracting a specific file
        //extractor.extractMatching("path/to/archive.7z", "file.pdf", "out/dir/");
        // Extracting the first file of an archive to a buffer
        //std::vector< byte_t > buffer;
        //extractor.extract("path/to/archive.7z", buffer);
        // Extracting an encrypted archive
        //extractor.setPassword("password");
        //extractor.extract("path/to/another/archive.7z", "out/dir/");
    }
    catch (const bit7z::BitException& ex) {
        printf(ex.what());
    }
    return 0;
}

总结

主要参考这个文章的:!!!C++ 7z解压缩编译及使用!!!

参考:

7z源码的编译与使用_markdown 格式

7z文件格式及其源码的分析(二)

笔记:7-zip在Visual Studio 2019下的编译

c++配置并使用bit7z加密压缩或解压7z文件


相关文章
|
网络协议 IDE Linux
mongoose使用详细 -- 如何通过mongoose搭建服务器
mongoose使用详细 -- 如何通过mongoose搭建服务器
2954 0
|
存储 缓存 NoSQL
Leveldb学习笔记:leveldb的使用与原理探究
Leveldb学习笔记:leveldb的使用与原理探究
Leveldb学习笔记:leveldb的使用与原理探究
|
Unix 编译器 开发者
Qt5.14.2 轻松掌握Qt中的压缩与解压缩:QuaZIP的神秘面纱与实战演练之windows环境编译
Qt5.14.2 轻松掌握Qt中的压缩与解压缩:QuaZIP的神秘面纱与实战演练之windows环境编译
1841 0
|
Windows
Qt5.14.2 轻松掌握Qt中的压缩与解压缩:QuaZIP的神秘面纱与实战演练之使用QuaZIP
Qt5.14.2 轻松掌握Qt中的压缩与解压缩:QuaZIP的神秘面纱与实战演练之使用QuaZIP
733 0
|
API PHP C++
Windows下用vs2017编译和配置libcurl库(手把手教,适合新人)
Windows下用vs2017编译和配置libcurl库(手把手教,适合新人)
3003 0
|
算法 Java Linux
7-zip 压缩算法及C SDK使用
7-zip 压缩算法及C SDK使用
2129 0
|
安全 测试技术 C++
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
最近用到了gRPC,配置了很长时间,分享一下配置过程。先来看一下我准备的文件包(资源我放在最后)
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
|
算法 Unix Linux
7z——拥有极高压缩比的开源压缩软件
【11月更文挑战第6天】7z 是一种开源压缩软件,具有高压缩比、开源特性、功能丰富、跨平台支持和良好兼容性等特点。它采用先进的压缩算法,支持大文件、加密和多种压缩格式,广泛应用于个人和企业文件管理。
1829 3
|
存储 前端开发 C++
C++ 多线程之带返回值的线程处理函数
这篇文章介绍了在C++中使用`async`函数、`packaged_task`和`promise`三种方法来创建带返回值的线程处理函数。
783 6

热门文章

最新文章

下一篇
开通oss服务