• 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 
16 #ifndef FOUNDATION_AAFWK_STANDARD_TOOLS_ZIP_INTERNAL_H
17 #define FOUNDATION_AAFWK_STANDARD_TOOLS_ZIP_INTERNAL_H
18 
19 #include <string>
20 #include <time.h>
21 #include "contrib/minizip/unzip.h"
22 #include "contrib/minizip/zip.h"
23 #include "zip_utils.h"
24 
25 namespace OHOS {
26 namespace AAFwk {
27 namespace LIBZIP {
28 namespace {
29 const int kZipMaxPath = 256;
30 const int kZipBufSize = 8192;
31 }  // namespace
32 
33 // Callback function for zlib that opens a file stream from a file descriptor.
34 // Since we do not own the file descriptor, dup it so that we can fdopen/fclose
35 // a file stream.
36 void *FdOpenFileFunc(void *opaque, const char *filename, int mode);
37 
38 int FdCloseFileFunc(void *opaque, void *stream);
39 
40 // Fills |pzlib_filecunc_def| appropriately to handle the zip file
41 // referred to by |fd|.
42 void FillFdOpenFileFunc(zlib_filefunc_def *pzlibFilefuncDef, PlatformFile fd);
43 
44 unzFile OpenFdForUnzipping(PlatformFile zipFD);
45 
46 struct tm GetTmDataFromTickts(int64_t ticks);
47 
48 unzFile OpenForUnzipping(std::string &fileNameUtf8);
49 
50 // Opens the file referred to by |zipFD| for unzipping.
51 unzFile OpenFdForUnzipping(int zipFD);
52 
53 // Creates a custom unzFile object which reads data from the specified string.
54 // This custom unzFile object overrides the I/O API functions of zlib so it can
55 // read data from the specified string.
56 unzFile PrepareMemoryForUnzipping(const std::string &data);
57 
58 // Opens the given file name in UTF-8 for zipping, with some setup for
59 // Windows. |append_flag| will be passed to zipOpen2().
60 zipFile OpenForZipping(const std::string &fileNameUtf8, int appendFlag);
61 
62 // Opens the file referred to by |zipFD| for zipping. |append_flag| will be
63 // passed to zipOpen2().
64 zipFile OpenFdForZipping(PlatformFile zipFd, int appendFlag);
65 
66 bool ZipOpenNewFileInZip(
67     zipFile zipFile, const std::string &strPath, const OPTIONS &options, const struct tm *lastModifiedTime);
68 
69 }  // namespace LIBZIP
70 }  // namespace AAFwk
71 }  // namespace OHOS
72 
73 #endif  // FOUNDATION_AAFWK_STANDARD_TOOLS_ZIP_INTERNAL_H
74