POCO::ZIP 压缩与解压缩文件夹

时间:2022-03-25 11:50:42
 
//! 压缩目录到某个目录下的ZIP文件
/*!
	\param desfile	目标文件,如D:\\test.zip
	\param srcdir	源目录(要压缩的文件夹路径),如D:\\test\\
*/
void CModeSectionMgr::zipDirectory(char * desfile, char * srcdir)
{
	Poco::Path srcdir_path(srcdir);
	srcdir_path.makeDirectory();	

	std::ofstream outstream(desfile, std::ios::binary);

	Poco::Zip::Compress compress(outstream, true);
	compress.addRecursive(srcdir_path, Poco::Zip::ZipCommon::CL_NORMAL);

	compress.close();
	outstream.close();	
}

//! 解压缩ZIP文件到某个目录
/*!
	\param desdir	目标目录(要解压到的文件夹路径),如D:\\test\\
	\param srcfile	源压缩文件,如D:\\test.zip
*/
void CModeSectionMgr::unZipDirectory(char * desdir, char * srcfile)
{
	std::ifstream instream(srcfile, std::ios::binary);

	Poco::Zip::Decompress decompress(instream, desdir); 
	decompress.decompressAllFiles();

	instream.close();
}