• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_
6 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_
7 
8 #include <string>
9 
10 #include "base/time/time.h"
11 #include "build/build_config.h"
12 
13 #if defined(OS_WIN)
14 #include <windows.h>
15 #endif
16 
17 #if defined(USE_SYSTEM_MINIZIP)
18 #include <minizip/unzip.h>
19 #include <minizip/zip.h>
20 #else
21 #include "third_party/zlib/contrib/minizip/unzip.h"
22 #include "third_party/zlib/contrib/minizip/zip.h"
23 #endif
24 
25 namespace base {
26 class FilePath;
27 }
28 
29 // Utility functions and constants used internally for the zip file
30 // library in the directory. Don't use them outside of the library.
31 namespace zip {
32 namespace internal {
33 
34 // Opens the given file name in UTF-8 for unzipping, with some setup for
35 // Windows.
36 unzFile OpenForUnzipping(const std::string& file_name_utf8);
37 
38 #if defined(OS_POSIX) || defined(OS_FUCHSIA)
39 // Opens the file referred to by |zip_fd| for unzipping.
40 unzFile OpenFdForUnzipping(int zip_fd);
41 #endif
42 
43 #if defined(OS_WIN)
44 // Opens the file referred to by |zip_handle| for unzipping.
45 unzFile OpenHandleForUnzipping(HANDLE zip_handle);
46 #endif
47 
48 // Creates a custom unzFile object which reads data from the specified string.
49 // This custom unzFile object overrides the I/O API functions of zlib so it can
50 // read data from the specified string.
51 unzFile PrepareMemoryForUnzipping(const std::string& data);
52 
53 // Opens the given file name in UTF-8 for zipping, with some setup for
54 // Windows. |append_flag| will be passed to zipOpen2().
55 zipFile OpenForZipping(const std::string& file_name_utf8, int append_flag);
56 
57 #if defined(OS_POSIX) || defined(OS_FUCHSIA)
58 // Opens the file referred to by |zip_fd| for zipping. |append_flag| will be
59 // passed to zipOpen2().
60 zipFile OpenFdForZipping(int zip_fd, int append_flag);
61 #endif
62 
63 // Compression methods.
64 enum Compression {
65   kStored = 0,             // Stored (no compression)
66   kDeflated = Z_DEFLATED,  // Deflated
67 };
68 
69 // Adds a file (or directory) entry to the ZIP archive.
70 bool ZipOpenNewFileInZip(zipFile zip_file,
71                          const std::string& str_path,
72                          base::Time last_modified_time,
73                          Compression compression);
74 
75 // Selects the best compression method for the given file. The heuristic is
76 // based on the filename extension. By default, the compression method is
77 // kDeflated. But if the given path has an extension indicating a well known
78 // file format which is likely to be already compressed (eg ZIP, RAR, JPG,
79 // PNG...) then the compression method is simply kStored.
80 Compression GetCompressionMethod(const base::FilePath& path);
81 
82 const int kZipMaxPath = 256;
83 const int kZipBufSize = 8192;
84 
85 }  // namespace internal
86 }  // namespace zip
87 
88 #endif  // THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_
89