Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
forked fromrikyoz/bit7z

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.

License

NotificationsYou must be signed in to change notification settings

Pospelove/bit7z

 
 

Repository files navigation

A C++ static library offering a clean and simple interface to the 7-zip shared libraries

Supported FeaturesGetting StartedDownloadRequirementsBuilding & UsingDonateLicense

GitHub releaseC++14/17WindowsLinuxmacOSx86, x64donatedocsBuild status
MSVC 2015+MinGW 6.4+GCC 4.9+Clang 3.5+CodeFactor GradeLicense

⚡️ Introduction

bit7z is across-platform C++ static library that allows thecompression/extraction of archive files through aclean andsimple wrapper interface to the dynamic libraries from the7-zip project.
It supports compression and extraction to and from the filesystem or the memory, reading archives metadata, updating existing ones, creating multi-volume archives, operation progress callbacks, and many other functionalities.

🎯 Supported Features

  • Compression using the following archive formats:7z, XZ,BZIP2,GZIP, TAR,ZIP, and WIM.
  • Extraction of many archive formats: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, andZIP.
  • Reading metadata of archives and their content.
  • Testing archives for errors.
  • Updating existing file archives with new files.
  • Renaming,updating, ordeleting old items in existing file archives.
  • Compression and extractionto and from memory andC++ standard streams.
  • Compression usingcustom path aliases for the items in the output archives.
  • Selective extraction of only specified files/foldersusing wildcards andregular expressions.
  • Creation ofencrypted archives (strong AES-256 encryption — only for 7z and ZIP formats).
  • Archive header encryption (only for 7z format).
  • Possibility to choose thecompression level (if supported by the archive format), thecompression method (supported methods), thedictionary size, and theword size.
  • Automatic input archive format detection.
  • Solid archives (only for 7z).
  • Multi-volume archives.
  • Operation callbacks for obtaining real-time information about ongoing operations.
  • Canceling orpausing the current operation.

Notes

The presence or not of some of the above features depends on the particular shared library used along with bit7z.
For example, 7z.dll should support all these features, 7za.dll should work only with the 7z file format, and 7zxa.dll can only extract 7z files. For more information about the 7-zip DLLs, please check thiswiki page.

In the end, some other features (e.g.,automatic format detection andselective extraction using regular expressions) are disabled by default, and macro definitions must be used during compilation to have them available (wiki).

🔥 Getting Started (Library Usage)

Below are a few examples that show how to use some of the main features of bit7z.

📂 Extracting files from an archive

#include<bit7z/bitfileextractor.hpp>try {// bit7z classes can throw BitException objectsusingnamespacebit7z;    Bit7zLibrary lib{"7za.dll" };    BitFileExtractor extractor{ lib, BitFormat::SevenZip };// Extracting a simple archive    extractor.extract("path/to/archive.7z","out/dir/" );// 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 ) {/* Do something with ex.what()...*/ }

Alternatively, if you only need to work on a single archive:

#include<bit7z/bitarchivereader.hpp>try {// bit7z classes can throw BitException objectsusingnamespacebit7z;    Bit7zLibrary lib{"7z.dll" };// Opening the archive    BitArchiveReader reader{lib,"path/to/archive.gz", BitFormat::GZip };// Testing the archive    reader.test();// Extracting the archive    reader.extract("out/dir/" );}catch (const bit7z::BitException& ex ) {/* Do something with ex.what()...*/ }

💼 Compressing files into an archive

#include<bit7z/bitfilecompressor.hpp>try {// bit7z classes can throw BitException objectsusingnamespacebit7z;    Bit7zLibrary lib{"7z.dll" };    BitFileCompressor compressor{ lib, BitFormat::Zip };    std::vector< std::string > files = {"path/to/file1.jpg","path/to/file2.pdf" };// Creating a simple zip archive    compressor.compress( files,"output_archive.zip" );// Creating a zip archive with a custom directory structure    std::map< std::string, std::string > files_map = {        {"path/to/file1.jpg","alias/path/file1.jpg" },        {"path/to/file2.pdf","alias/path/file2.pdf" }    };    compressor.compress( files_map,"output_archive2.zip" );// Compressing a directory    compressor.compressDirectory("dir/path/","dir_archive.zip" );// Creating an encrypted zip archive of two files    compressor.setPassword("password" );    compressor.compressFiles( files,"protected_archive.zip" );// Updating an existing zip archive    compressor.setUpdateMode( UpdateMode::Append );    compressor.compressFiles( files,"existing_archive.zip" );// Compressing a single file into a buffer    std::vector< bit7z::byte_t > buffer;    BitFileCompressor compressor2{ lib, BitFormat::BZip2 };    compressor2.compressFile( files[0], buffer );}catch (const bit7z::BitException& ex ) {/* Do something with ex.what()...*/ }

Alternatively, if you only need to work on a single archive:

#include<bit7z/bitarchivewriter.hpp>try {// bit7z classes can throw BitException objectsusingnamespacebit7z;    Bit7zLibrary lib{"7z.dll" };    BitArchiveWriter writer{lib, BitFormat::SevenZip };// Adding the items to be compressed (no compression is performed here)    writer.addFile("path/to/file.txt" );    writer.addDirectory("path/to/dir/" );// Compressing the added items to the output archive    writer.compressTo("output.7z" );}catch (const bit7z::BitException& ex ) {/* Do something with ex.what()...*/ }

📑 Reading archive metadata

#include<bit7z/bitarchivereader.hpp>try {// bit7z classes can throw BitException objectsusingnamespacebit7z;    Bit7zLibrary lib{"7za.dll" };    BitArchiveReader arc{ lib,"archive.7z", BitFormat::SevenZip };// Printing archive metadata    std::cout <<"Archive properties" << std::endl;    std::cout <<"  Items count:"   << arc.itemsCount() << std::endl;    std::cout <<"  Folders count:" << arc.foldersCount() << std::endl;    std::cout <<"  Files count:"   << arc.filesCount() << std::endl;    std::cout <<"  Size:"          << arc.size() << std::endl;    std::cout <<"  Packed size:"   << arc.packSize() << std::endl;    std::cout << std::endl;// Printing the metadata of the archived items    std::cout <<"Archived items";auto arc_items = arc.items();for (auto& item : arc_items ) {        std::cout << std::endl;        std::cout <<"  Item index:"   << item.index() << std::endl;        std::cout <<"    Name:"        << item.name() << std::endl;        std::cout <<"    Extension:"   << item.extension() << std::endl;        std::cout <<"    Path:"        << item.path() << std::endl;        std::cout <<"    IsDir:"       << item.isDir() << std::endl;        std::cout <<"    Size:"        << item.size() << std::endl;        std::cout <<"    Packed size:" << item.packSize() << std::endl;        std::cout <<"    CRC:"         << item.crc() << std::endl;    }}catch (const bit7z::BitException& ex ) {/* Do something with ex.what()...*/ }

A completeAPI reference is available in thewiki section.

🚀 Upgrading from bit7z v3 to v4

Expand for more details!

The newest bit7z v4 introduced some significant breaking changes to the API. In particular:

  • By default, the project now follows theUTF-8 Everywhere Manifesto:
    • The default string type isstd::string (instead ofstd::wstring), so users can use the library in cross-platform projects more easily (v4 introduced Linux/macOS support too).
    • Inputstd::strings will be considered as UTF-8 encoded.
    • You can still achieve the old behavior on Windows using the-DBIT7Z_USE_NATIVE_STRING CMake option.
  • The oldBitExtractor class is now calledBitFileExtractor.
    • NowBitExtractor is just the name of a template class for all the extraction classes.
  • The oldBitCompressor class is now calledBitFileCompressor.
    • NowBitCompressor is just the name of a template class for all the compression classes.
  • TheProgressCallback now must return abool value indicating whether the current operation can continue (true) or not (false).

💾 Download

GitHub Latest Release  GitHub Stable Release
GitHub All Releases

Each released package contains:

  • Apre-compiled version of bit7z (both indebug andrelease mode);
  • Thepublic API headers needed to use the library in your program;

Packages are available for bothx86 andx64 architectures.

You can also clone/download this repository and build the library by yourself (please, read thewiki).

🧰 Requirements

  • Operating System: Windows, Linux, macOS1.
  • Architecture: x86, x86_64.
  • Compiler: MSVC 2015 or later2, MinGW v6.4 or later, GCC v4.9 or later, Clang 3.5 or later.
  • Shared Library: a 7-zip.dll library on Windows, a 7-zip/p7zip.so library on Unix3.

⚙️ Building and using bit7z

For building the library:

cd<bit7z folder>mkdir build&&cd buildcmake ../ -DCMAKE_BUILD_TYPE=Releasecmake --build. -j --config Release

A more detailed guide on how to build this library is availablehere.

You can directly integrate the library into your project via CMake:

  • Download bit7z and copy it into a sub-directory of your project (e.g.,third_party), or add it as a git submodule of your repository.
  • You can then use the commandadd_subdirectory() in yourCMakeLists.txt to include bit7z.
  • Finally, add thebit7z64 target (justbit7z on x86) using thetarget_link_libraries() command.

For example:

add_subdirectory(${CMAKE_SOURCE_DIR}/third_party/bit7z )target_link_libraries(${TARGET_NAME}PRIVATE bit7z64 )# or bit7z on x86

☕️ Donate

If you have found this project helpful, please consider supporting me with a small donation so that I can keep improving it!Thank you! 🙏

Sponsor me on GitHubBuy Me a Coffee at ko-fi.comDonations

📜 License

This project is licensed under the terms of theMozilla Public License v2.0.
For more details, please check:

Older versions (v3.x and earlier) of bit7z were released under theGNU General Public License v2.


Copyright © 2014 - 2023 Riccardo Ostani (@rikyoz)

Footnotes

  1. On Windows, you should link your programalso witholeaut32 (e.g.,-lbit7z -loleaut32).
    On Linux and macOS, you should link your programalso withdl (e.g.,-lbit7z -ldl).
    If you are using the library via CMake, these dependencies will be linked automatically to your project.

  2. MSVC 2010 was supported until v2.x, MSVC 2012/2013 until v3.x.

  3. bit7z doesn't ship with the 7-zip shared libraries. You can build them from the source code available at7-zip.org.

About

A C++ static library offering a clean and simple interface to the 7-zip shared libraries.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++95.7%
  • CMake4.3%

[8]ページ先頭

©2009-2025 Movatter.jp