Libzippp是Libzip库周围的简单基本C ++包装器。它本来是一个用于拉链处理的便携式且易于使用的库。
汇编已通过:
基础图书馆:
有关可用压缩方法的更多信息,请参见此处。
Libzippp已移植到VCPKG,因此可以通过运行非常容易集成:
./vcpkg install libzippp
该库至少需要编译C ++ 11。
Linux
zlib1g-dev , libzip-dev , liblzma-dev , libbz2-dev )。make libraries来使用makefile。视窗:
所有操作系统
LIBZIPPP_ENABLE_ENCRYPTION在Libzippp中启用它。mkdir build
cd build
cmake ..
make
make installmkdir build && cd buildcmake .. -DCMAKE_BUILD_TYPE=ReleaseAdd Cache Entry以添加CMAKE_BUILD_TYPE如果不使用MSVC构建)Configure和GenerateCMAKE_PREFIX_PATH设置为将其安装到的目录中(通过-DCMAKE_PREFIX_PATH=<...>或通过GUI)-DCMAKE_PREFIX_PATH=/home/user/libzip-1.11.2:/home/user/zlib-1.3.1make && make installINSTALL目标要安装。 通过Commandline设置为cmake -DNAME=VALUE <other opts>或通过CMAKE GUI或CCMAKE Add Cache Entry 。
LIBZIPPP_INSTALL :启用/禁用libzippp的安装。使用via add_subdirectory时默认值关闭LIBZIPPP_INSTALL_HEADERS :启用/禁用libzippp标头的安装。使用via add_subdirectory时默认值关闭LIBZIPPP_BUILD_TESTS :启用/禁用建筑物libzippp测试。使用via add_subdirectory时默认值关闭LIBZIPPP_ENABLE_ENCRYPTION :启用/禁用具有加密功能的libzippp。默认值关闭。LIBZIPPP_CMAKE_CONFIG_MODE :使用LIBZIP安装的CMake Config文件启用/禁用建筑物。默认值关闭。LIBZIPPP_GNUINSTALLDIRS :使用从gnuinstalldirs获取的安装目录启用/禁用建筑物。默认值关闭。CMAKE_INSTALL_PREFIX :在哪里安装项目CMAKE_BUILD_TYPE :设置释放或调试以构建有或没有优化CMAKE_PREFIX_PATH :以此使用的安装libs使用的前缀路径(包含lib的路径和include文件夹)的结肠分隔列表BUILD_SHARED_LIBS :设置为ON或OFF以构建共享或静态LIB,如果未设置,则使用平台默认一旦安装了Libzippp,就可以轻松地从任何CMAKE项目中使用:
鉴于将其安装到标准位置(通过CMAKE_INSTALL_PREFIX )或其安装前缀传递到您的项目中CMAKE_PREFIX_PATH您可以简单地调用find_package(libzippp 3.0 REQUIRED)并针对libzippp::libzippp链接。
当不使用cmake消耗libzippp时,您必须将其传递给您的编译器,并与libzippp.{a,so}链接。不要忘记也链接到与libzip库中的链接,例如在lib/libzip-1.11.2/lib/.libs/ )中链接。 G ++汇编的一个示例:
g++ -I./src
-I./lib/libzip-1.11.2/lib I./lib/libzip-1.11.2/build
main.cpp libzippp.a
lib/libzip-1.11.2/lib/.libs/libzip.a
lib/zlib-1.3.1/libz.a由于版本1.5,Libzip使用静态汇编所需的基础加密库(OpenSSL,Gnutls或CommonCrypto)。默认情况下,libzippp将使用-lssl -lcrypto (openSSL)作为默认标志来编译测试。可以通过使用make CRYPTO_FLAGS="-lsome_lib" LIBZIP_CMAKE="" tests来更改。
由于libzip cmake的文件会自动检测要使用的加密库,因此默认情况下所有允许的库,但OpenSSL在makefile的LIBZIP_CMAKE变量中明确禁用。
请参阅此处以获取更多信息。
最简单的方法是下载Zlib,Libzip和Libzippp来源,并使用CMAKE GUI按顺序构建每个库:
Source ,在其中Build到新的文件夹buildGenerate但是还有一个准备好的批处理文件可以帮助自动化此文件。不过,它可能需要进行一些调整。
确保您有CMAKE 3.20( CMAKE.EXE必须在路径中)和MS Visual Studio。
从版本中下载libzippp- <版本> -windows -ready_to_compile.zip文件,并在系统上的某个地方提取它。这将创建一个准备好的结构,因此可以与所需的库一起编译Libzippp 。
检查是否在LIB中使用任何补丁。有时,根据版本,有些文件在libzip中不可编译。
只需执行compile.bat文件即可。这将编译Zlib , Libzip和最后的Libzippp 。
您将拥有一个包含发行版和调试文件夹的DIST文件夹,现在可以在其中执行Libzippp测试。
确保您的CMAKE 3.10( CMAKE.EXE必须在路径中)和MS Visual Studio 2012。
下载libzip和zlib来源,然后在“ lib”文件夹中提取它们。您应该以以下结构结构:
libzippp/compile.bat
libzippp/lib/zlib-1.3.1
libzippp/lib/libzip-1.11.2
执行compile.bat (只需双击它)即可。汇编应该没有错误。
您将拥有一个包含发行版和调试文件夹的DIST文件夹,现在可以在其中执行Libzippp测试。
您可以使用libzippp.dll和libzippp.lib动态链接该库,也可以简单地使用libzippp_static.lib静态地链接它。除非您还静态地链接Zlib和Libzippp,否则您需要使用可执行文件包装的DLL。
API的意图是非常直接的。一些法国的解释可以在这里找到。
# include " libzippp.h "
using namespace libzippp ;
int main ( int argc, char ** argv) {
ZipArchive zf ( " archive.zip " );
zf. open (ZipArchive::ReadOnly);
vector<ZipEntry> entries = zf. getEntries ();
vector<ZipEntry>::iterator it;
for (it=entries. begin () ; it!=entries. end (); ++it) {
ZipEntry entry = *it;
string name = entry. getName ();
int size = entry. getSize ();
// the length of binaryData will be given by 'size'
void * binaryData = entry. readAsBinary ();
// the length of textData will be given by 'size'
string textData = entry. readAsText ();
// ...
}
zf. close ();
return 0 ;
}您还可以直接从缓冲区创建一个档案
# include " libzippp.h "
using namespace libzippp ;
int main ( int argc, char ** argv) {
char * buffer = someData;
uint32_t bufferSize = sizeOfBuffer;
ZipArchive* zf = ZipArchive::fromBuffer (buffer, bufferSize);
if (zf!= nullptr ) {
/* work with the ZipArchive instance */
zf-> close ();
delete zf;
}
return 0 ;
}# include " libzippp.h "
using namespace libzippp ;
int main ( int argc, char ** argv) {
ZipArchive zf ( " archive.zip " );
zf. open (ZipArchive::ReadOnly);
// raw access
char * data = ( char *)zf. readEntry ( " myFile.txt " , true );
ZipEntry entry1 = zf. getEntry ( " myFile.txt " );
string str1 (data, entry1. getSize ());
// text access
ZipEntry entry2 = zf. getEntry ( " myFile.txt " );
string str2 = entry2. readAsText ();
zf. close ();
return 0 ;
}# include " libzippp.h "
using namespace libzippp ;
int main ( int argc, char ** argv) {
ZipArchive zf ( " archive.zip " );
zf. open (ZipArchive::ReadOnly);
ZipEntry largeEntry = z1. getEntry ( " largeentry " );
std::ofstream ofUnzippedFile ( " largeFileContent.data " );
largeEntry. readContent (ofUnzippedFile);
ofUnzippedFile. close ();
zf. close ();
return 0 ;
}# include " libzippp.h "
using namespace libzippp ;
int main ( int argc, char ** argv) {
ZipArchive zf ( " archive.zip " );
zf. open (ZipArchive::Write);
# ifdef LIBZIPPP_USE_BZIP2
// Advanced usage : change the compression method. Default is DEFLATE.
zf. setCompressionMethod (entry, CompressionMethod::BZIP2);
# endif
zf. addEntry ( " folder/subdir/ " );
const char * textData = " Hello,World! " ;
zf. addData ( " helloworld.txt " , textData, 12 );
zf. close ();
return 0 ;
}# include " libzippp.h "
using namespace libzippp ;
int main ( int argc, char ** argv) {
ZipArchive zf ( " archive.zip " );
zf. open (ZipArchive::Write);
zf. deleteEntry ( " myFile.txt " );
zf. deleteEntry ( " myDir/subDir/ " );
zf. close ();
return 0 ;
}# include " libzippp.h "
using namespace libzippp ;
class SimpleProgressListener : public ZipProgressListener {
public:
SimpleProgressListener ( void ) {}
virtual ~SimpleProgressListener ( void ) {}
void progression ( double p) {
cout << " -- Progression: " << p << endl;
}
};
int main ( int argc, char ** argv) {
ZipArchive zf ( " archive.zip " );
/* add/modify/delete entries in the archive */
// register the listener
SimpleProgressListener spl;
zf. addProgressListener (&spl);
// adjust how often the listener will be invoked
zf. setProgressPrecision ( 0.1 );
// listener will be invoked
zf. close ();
return 0 ;
}# include " libzippp.h "
using namespace libzippp ;
int main ( int argc, char ** argv) {
// important to use calloc/malloc for the fromWritableBuffer !
void * buffer = calloc ( 4096 , sizeof ( char ));
ZipArchive* z1 = ZipArchive::fromWritableBuffer (&buffer, 4096 , ZipArchive::New);
/* add content to the archive */
// updates the content of the buffer
z1-> close ();
// length of the buffer content
int bufferContentLength = z1-> getBufferLength ();
ZipArchive::free (z1);
// read again from the archive:
ZipArchive* z2 = ZipArchive::fromBuffer (buffer, bufferContentLength);
/* read the archive - no modification allowed */
ZipArchive::free (z2);
// read again from the archive, for modification:
ZipArchive* z3 = ZipArchive::fromWritableBuffer (&buffer, bufferContentLength);
/* read/write the archive */
ZipArchive::free (z3);
free (buffer);
return 0 ;
}默认情况下,错误处理非常基本,并且错误详细信息被倾倒到stderr 。但是,可以提供一种回调方法来覆盖此行为。如果需要一些上下文,则可以使用std::bind或lambda命令。
# include " libzippp.h "
using namespace libzippp ;
int main ( int argc, char ** argv) {
ZipArchive zf ( " archive.zip " );
zf. setErrorHandlerCallback ([]( const std::string& message,
const std::string& strerror ,
int zip_error_code,
int system_error_code)
{
// Handle error here
fprintf (stderr, message. c_str (), strerror . c_str ());
});
zf. open (ZipArchive::Write);
zf. addEntry ( " folder/subdir/ " );
const char * textData = " Hello,World! " ;
zf. addData ( " helloworld.txt " , textData, 12 );
zf. close ();
return 0 ;
}您可能已经在系统上其他地方编译了Libzip。因此,您不需要运行“制作libzip”。相反,只需在编译Libzippp时放置Libzip位置:
make LIBZIP=path/to/libzip在Debian的领导下,如果您不想手动安装Zlib,则必须安装软件包zlib1g-dev 。
默认情况下,MS Visual Studio 2012安装在以下路径下:
C:Program Files (x86)Microsoft Visual Studio 11.0
请注意,在libzippp的dll中共享非虚拟类别。因此,您需要将相同的编译器用于Libzippp以及将使用它的代码。为了避免此问题,您必须静态地链接库。
更多信息在这里。
可以在这里找到额外的解释。
这个项目是在我的业余时间完全开发的。
由于我是加密货币(尤其是Cardano(ADA))的忠实拥护者,因此您可以在下面的地址向我发送一些硬币(请在此处检查):
addr1q9sgms4vc038nq7hu4499yeszy0rsq3hjeu2k9wraksle8arg0n953hlsrtdzpfnxxw996l4t6qu5xsx8cmmakjcqhksaqpj66