OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "third_party/zlib/google/zip.h" | 5 #include "third_party/zlib/google/zip.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 std::string str_path = | 54 std::string str_path = |
55 path.AsUTF8Unsafe().substr(root_path.AsUTF8Unsafe().length() + 1); | 55 path.AsUTF8Unsafe().substr(root_path.AsUTF8Unsafe().length() + 1); |
56 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
57 ReplaceSubstringsAfterOffset(&str_path, 0u, "\\", "/"); | 57 ReplaceSubstringsAfterOffset(&str_path, 0u, "\\", "/"); |
58 #endif | 58 #endif |
59 | 59 |
60 bool is_directory = base::DirectoryExists(path); | 60 bool is_directory = base::DirectoryExists(path); |
61 if (is_directory) | 61 if (is_directory) |
62 str_path += "/"; | 62 str_path += "/"; |
63 | 63 |
64 if (ZIP_OK != zipOpenNewFileInZip( | 64 // Section 4.4.4 http://www.pkware.com/documents/casestudies/APPNOTE.TXT |
65 zip_file, str_path.c_str(), | 65 // Setting the Language encoding flag so the file is told to be in utf-8. |
66 NULL, NULL, 0u, NULL, 0u, NULL, // file info, extrafield local, length, | 66 const unsigned long LANGUAGE_ENCODING_FLAG = 0x1 << 11; |
67 // extrafield global, length, comment | 67 |
68 Z_DEFLATED, Z_DEFAULT_COMPRESSION)) { | 68 if (ZIP_OK != zipOpenNewFileInZip4( |
| 69 zip_file, //file |
| 70 str_path.c_str(), // filename |
| 71 NULL, // zipfi (file_info) |
| 72 NULL, // extrafield_local, |
| 73 0u, // size_extrafield_local |
| 74 NULL, // extrafield_global |
| 75 0u, // size_extrafield_global |
| 76 NULL, // comment |
| 77 Z_DEFLATED, // method |
| 78 Z_DEFAULT_COMPRESSION, // level |
| 79 0, // raw |
| 80 -MAX_WBITS, // windowBits |
| 81 DEF_MEM_LEVEL, // memLevel |
| 82 Z_DEFAULT_STRATEGY, // strategy |
| 83 NULL, //password |
| 84 0, // crcForCrypting |
| 85 0, // versionMadeBy |
| 86 LANGUAGE_ENCODING_FLAG)) { // flagBase |
69 DLOG(ERROR) << "Could not open zip file entry " << str_path; | 87 DLOG(ERROR) << "Could not open zip file entry " << str_path; |
70 return false; | 88 return false; |
71 } | 89 } |
72 | 90 |
73 bool success = true; | 91 bool success = true; |
74 if (!is_directory) { | 92 if (!is_directory) { |
75 success = AddFileToZip(zip_file, path); | 93 success = AddFileToZip(zip_file, path); |
76 } | 94 } |
77 | 95 |
78 if (ZIP_OK != zipCloseFileInZip(zip_file)) { | 96 if (ZIP_OK != zipCloseFileInZip(zip_file)) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 if (ZIP_OK != zipClose(zip_file, NULL)) { | 216 if (ZIP_OK != zipClose(zip_file, NULL)) { |
199 DLOG(ERROR) << "Error closing zip file for fd " << dest_fd; | 217 DLOG(ERROR) << "Error closing zip file for fd " << dest_fd; |
200 success = false; | 218 success = false; |
201 } | 219 } |
202 | 220 |
203 return success; | 221 return success; |
204 } | 222 } |
205 #endif // defined(OS_POSIX) | 223 #endif // defined(OS_POSIX) |
206 | 224 |
207 } // namespace zip | 225 } // namespace zip |
OLD | NEW |