Last active
October 19, 2023 05:02
-
-
Save selfboot/acda3473f687f610dc1f6230e555df03 to your computer and use it in GitHub Desktop.
Revisions
-
selfboot revised this gist
Oct 19, 2023 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,15 +3,14 @@ #include <string> #include <vector> struct FileInfo { std::string htmltemlate; std::string filename; }; int main() { std::vector<FileInfo> FileInfos = { {R"(<?xml version="1.0" encoding="utf-8" standalone="no"?>demo)", "file1"}, }; const char *tmpFile = "example.zip"; @@ -24,7 +23,7 @@ int main() { } zip_source* s = NULL; for (auto item : FileInfos) { if (NULL == (s = zip_source_buffer(archive, item.htmltemlate.c_str(), item.htmltemlate.size(), 0)) || zip_file_add(archive, (item.filename + "_temp.xhtml").c_str(), s, ZIP_FL_ENC_UTF_8 | ZIP_FL_OVERWRITE) < 0) { zip_source_free(s); -
selfboot created this gist
Oct 18, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ #include <zip.h> #include <iostream> #include <string> #include <vector> struct CopyrightInfo { std::string htmltemlate; std::string filename; }; int main() { std::vector<CopyrightInfo> copyrightInfos = { {"<html>Content 1</html>", "file1"}, {"<html>Content 2</html>", "file2"} }; const char *tmpFile = "example.zip"; int error = 0; zip* archive = zip_open(tmpFile, ZIP_CREATE | ZIP_TRUNCATE, &error); if (archive == NULL) { printf("fail to open %s err %d", tmpFile, error); return 1; } zip_source* s = NULL; for (auto item : copyrightInfos) { if (NULL == (s = zip_source_buffer(archive, item.htmltemlate.c_str(), item.htmltemlate.size(), 0)) || zip_file_add(archive, (item.filename + "_temp.xhtml").c_str(), s, ZIP_FL_ENC_UTF_8 | ZIP_FL_OVERWRITE) < 0) { zip_source_free(s); printf("fail to add info.txt err %s", zip_strerror(archive)); error = -1; } } if (zip_close(archive) < 0) { printf("fail to close %s ret %d", tmpFile, error); return 1; } return 0; }