Loading repository data…
Loading repository data…
rikyoz / repository
A C++ static library offering a clean and simple interface to the 7-zip shared libraries.
bit7z is a cross-platform C++ static library that allows the compression/extraction of archive files through a clean and simple wrapper interface to the dynamic libraries from the 7-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.
[!NOTE]
The presence or not of some of the above features depends on the specific 7-Zip shared library used.
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 this wiki page.
[!NOTE]
Some features (e.g., automatic format detection and selective extraction using regular expressions) are disabled by default, and macro definitions must be used during compilation to have them available (wiki).
Below are a few examples that show how to use some of the main features of bit7z.
#include <bit7z/bitfileextractor.hpp>
try { // bit7z classes can throw BitException objects
using namespace bit7z;
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 inside an archive
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 objects
using namespace bit7z;
Bit7zLibrary lib{ "7z.dll" };
// Opening the archive
BitArchiveReader archive{ lib, "path/to/archive.gz", BitFormat::GZip };
// Testing the archive
archive.test();
// Extracting the archive
archive.extractTo( "out/dir/" );
} catch ( const bit7z::BitException& ex ) { /* Do something with ex.what()...*/ }
#include <bit7z/bitfilecompressor.hpp>
try { // bit7z classes can throw BitException objects
using namespace bit7z;
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" );