Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: third_party/zlib/google/zip_internal.h

Issue 179963002: New Zip::ZipFromMemory API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_ 5 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_
6 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_ 6 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_
7 7
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <windows.h> 9 #include <windows.h>
10 #endif 10 #endif
11 11
12 #include <map>
12 #include <string> 13 #include <string>
13 14
15 #include "base/strings/string_piece.h"
16
14 #if defined(USE_SYSTEM_MINIZIP) 17 #if defined(USE_SYSTEM_MINIZIP)
15 #include <minizip/unzip.h> 18 #include <minizip/unzip.h>
16 #include <minizip/zip.h> 19 #include <minizip/zip.h>
17 #else 20 #else
18 #include "third_party/zlib/contrib/minizip/unzip.h" 21 #include "third_party/zlib/contrib/minizip/unzip.h"
19 #include "third_party/zlib/contrib/minizip/zip.h" 22 #include "third_party/zlib/contrib/minizip/zip.h"
20 #endif 23 #endif
21 24
25 namespace base {
26 class FilePath;
27 class Time;
28 }
29
22 // Utility functions and constants used internally for the zip file 30 // Utility functions and constants used internally for the zip file
23 // library in the directory. Don't use them outside of the library. 31 // library in the directory. Don't use them outside of the library.
24 namespace zip { 32 namespace zip {
25 namespace internal { 33 namespace internal {
26 34
27 // Opens the given file name in UTF-8 for unzipping, with some setup for 35 // Opens the given file name in UTF-8 for unzipping, with some setup for
28 // Windows. 36 // Windows.
29 unzFile OpenForUnzipping(const std::string& file_name_utf8); 37 unzFile OpenForUnzipping(const std::string& file_name_utf8);
30 38
31 #if defined(OS_POSIX) 39 #if defined(OS_POSIX)
32 // Opens the file referred to by |zip_fd| for unzipping. 40 // Opens the file referred to by |zip_fd| for unzipping.
33 unzFile OpenFdForUnzipping(int zip_fd); 41 unzFile OpenFdForUnzipping(int zip_fd);
34 #endif 42 #endif
35 43
36 #if defined(OS_WIN) 44 #if defined(OS_WIN)
37 // Opens the file referred to by |zip_handle| for unzipping. 45 // Opens the file referred to by |zip_handle| for unzipping.
38 unzFile OpenHandleForUnzipping(HANDLE zip_handle); 46 unzFile OpenHandleForUnzipping(HANDLE zip_handle);
39 #endif 47 #endif
40 48
41 // Creates a custom unzFile object which reads data from the specified string. 49 // Creates a custom unzFile object which reads data from the specified string.
42 // This custom unzFile object overrides the I/O API functions of zlib so it can 50 // This custom unzFile object overrides the I/O API functions of zlib so it can
43 // read data from the specified string. 51 // read data from the specified string.
44 unzFile PreprareMemoryForUnzipping(const std::string& data); 52 unzFile PrepareMemoryForUnzipping(const std::string& data);
45 53
46 // Opens the given file name in UTF-8 for zipping, with some setup for 54 // Opens the given file name in UTF-8 for zipping, with some setup for
47 // Windows. |append_flag| will be passed to zipOpen2(). 55 // Windows. |append_flag| will be passed to zipOpen2().
48 zipFile OpenForZipping(const std::string& file_name_utf8, int append_flag); 56 zipFile OpenForZipping(const std::string& file_name_utf8, int append_flag);
49 57
50 #if defined(OS_POSIX) 58 #if defined(OS_POSIX)
51 // Opens the file referred to by |zip_fd| for zipping. |append_flag| will be 59 // Opens the file referred to by |zip_fd| for zipping. |append_flag| will be
52 // passed to zipOpen2(). 60 // passed to zipOpen2().
53 zipFile OpenFdForZipping(int zip_fd, int append_flag); 61 zipFile OpenFdForZipping(int zip_fd, int append_flag);
54 #endif 62 #endif
55 63
64 // Returns a zip_fileinfo with the last modification date of |path| set.
65 zip_fileinfo GetFileInfoForZipping(const base::FilePath& path);
66
67 // Wrapper around zipOpenNewFileInZip4 which passes most common options.
68 bool ZipOpenNewFileInZipWrapper(zipFile zip_file,
69 const std::string& str_path,
70 const zip_fileinfo* file_info);
71
72 // Adds to |zip_file| files using contents from memory. |zip_file| is created if
73 // it does not exist. |files| contains a map with the file path to
74 // be stored in the zip file plus its contents. The FilePath in |files| may not
75 // be empty, absolute or contain a '..' component, else the function fails.
76 // The paths must therefore be relative and preferably canonicalized.
77 // Calling this with an empty |files| has no effect.
78 //
79 // If |append| is true, the new files are appended to an already existing file,
80 // if any. Else, the file is recreated from scratch, meaning, all previous
81 // contents are deleted without the possibility of recovery.
82 //
83 // If the StringPiece in |files| is NULL, the file is removed from the zip
84 // archive. If the StringPiece in |files| is not NULL, a file will be
85 // created with those contents. The contents can have a size of 0 bytes.
86 // Note: the data passed in |files| is copied to the file. This function does
87 // not keep any references to the original data after it returns.
88 //
89 // If the FilePath ends with a path separator (a slash), a folder is created.
90 // Note: the contents for a folder must be either NULL or 0-byte big, so the
91 // folder will be removed or added, respectively.
92
93 typedef std::map<const base::FilePath, base::StringPiece> ZipContents;
94
95 bool ZipFromMemory(const base::FilePath& zip_path,
96 const ZipContents& files,
97 bool append);
98
satorux1 2014/03/24 06:16:07 Could you create a separate patch for this?
56 const int kZipMaxPath = 256; 99 const int kZipMaxPath = 256;
57 const int kZipBufSize = 8192; 100 const int kZipBufSize = 8192;
58 101
59 } // namespace internal 102 } // namespace internal
60 } // namespace zip 103 } // namespace zip
61 104
62 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_ 105 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698