• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef HIDUMPER_UTIL_ZIP_WRITER_H
16 #define HIDUMPER_UTIL_ZIP_WRITER_H
17 #include <string>
18 #include <vector>
19 #include "contrib/minizip/zip.h"
20 #include "util/zip/zip_common_type.h"
21 namespace OHOS {
22 namespace HiviewDFX {
23 class ZipWriter {
24 public:
25     ZipWriter(const std::string &zipFilePath);
26     ~ZipWriter();
27 public:
28     bool Open();
29     bool Close();
30     // zipItems: first:absolutePath, second:relativePath
31     bool Write(const std::vector<std::pair<std::string, std::string>> &zipItems,
32         const ZipTickNotify notify = nullptr);
33 private:
34     bool FlushItems(const ZipTickNotify notify = nullptr);
35     static bool SetTimeToZipFileInfo(zip_fileinfo &zipInfo);
36     static zipFile OpenForZipping(const std::string &fileName, int append);
37     static bool ZipOpenNewFileInZip(zipFile zip_file, const std::string &strPath);
38     static bool AddFileContentToZip(zipFile zip_file, std::string &file_path);
39     static bool OpenNewFileEntry(zipFile zip_file, std::string &path);
40     static bool CloseNewFileEntry(zipFile zip_file);
41     static bool AddFileEntryToZip(zipFile zip_file, std::string &relativePath, std::string &absolutePath);
42 private:
43     std::vector<std::pair<std::string, std::string>> zipItems_;
44     std::string zipFilePath_;
45     zipFile zipFile_;
46 };
47 } // namespace HiviewDFX
48 } // namespace OHOS
49 #endif // HIDUMPER_UTIL_ZIP_WRITER_H