OLD | NEW |
---|---|
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 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 4 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
5 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 5 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 // look like: | 28 // look like: |
29 // | 29 // |
30 // ZipReader reader; | 30 // ZipReader reader; |
31 // reader.Open(zip_file_path); | 31 // reader.Open(zip_file_path); |
32 // while (reader.HasMore()) { | 32 // while (reader.HasMore()) { |
33 // reader.OpenCurrentEntryInZip(); | 33 // reader.OpenCurrentEntryInZip(); |
34 // reader.ExtractCurrentEntryToDirectory(output_directory_path); | 34 // reader.ExtractCurrentEntryToDirectory(output_directory_path); |
35 // reader.AdvanceToNextEntry(); | 35 // reader.AdvanceToNextEntry(); |
36 // } | 36 // } |
37 // | 37 // |
38 // For simplicty, error checking is omitted in the example code above. The | 38 // For simplicity, error checking is omitted in the example code above. The |
39 // production code should check return values from all of these functions. | 39 // production code should check return values from all of these functions. |
40 // | 40 // |
41 // This calls can also be used for random access of contents in a zip file | 41 // This calls can also be used for random access of contents in a zip file |
42 // using LocateAndOpenEntry(). | 42 // using LocateAndOpenEntry(). |
43 // | 43 // |
44 class ZipReader { | 44 class ZipReader { |
45 public: | 45 public: |
46 // A callback that is called when the operation is successful. | 46 // A callback that is called when the operation is successful. |
47 typedef base::Closure SuccessCallback; | 47 typedef base::Closure SuccessCallback; |
48 // A callback that is called when the operation fails. | 48 // A callback that is called when the operation fails. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 // timestamp is not valid, the timestamp will be set to the current time. | 173 // timestamp is not valid, the timestamp will be set to the current time. |
174 bool ExtractCurrentEntryIntoDirectory( | 174 bool ExtractCurrentEntryIntoDirectory( |
175 const base::FilePath& output_directory_path); | 175 const base::FilePath& output_directory_path); |
176 | 176 |
177 #if defined(OS_POSIX) | 177 #if defined(OS_POSIX) |
178 // Extracts the current entry by writing directly to a file descriptor. | 178 // Extracts the current entry by writing directly to a file descriptor. |
179 // Does not close the file descriptor. Returns true on success. | 179 // Does not close the file descriptor. Returns true on success. |
180 bool ExtractCurrentEntryToFd(int fd); | 180 bool ExtractCurrentEntryToFd(int fd); |
181 #endif | 181 #endif |
182 | 182 |
183 // Extracts the current entry into memory. If the current entry is a directory | |
184 // the |output| parameter is set to the empty string. If the current entry is | |
185 // a file, the |output| parameter is filled with its contents. Returns true on | |
186 // success. OpenCurrentEntryInZip() must be called beforehand. | |
187 // Note: the |output| parameter can be filled with a big amount of data, avoid | |
188 // passing it around by value, but by reference or pointer. | |
189 // Note that EntryInfo::original_size() can return a different value than the | |
190 // real size of the uncompressed contents. Therefore, to prevent excessive | |
191 // memory usage, the maximum amount of data to read has to be specified in | |
192 // |max_read_bytes|. If the real size of the uncompressed data is bigger than | |
193 // max_read_bytes then false is returned. |max_read_bytes| must be positive | |
194 // non-zero. | |
hshi1
2014/03/19 17:33:27
nit: "positive non-zero" is redundant, just "posit
| |
195 bool ExtractCurrentEntryToString( | |
196 int max_read_bytes, | |
hshi1
2014/03/19 17:33:27
question: this seems to assume that data size cann
João Eiras
2014/03/20 13:52:45
size_t would be better, yes, though I wonder would
| |
197 std::string* output) const; | |
198 | |
183 // Returns the current entry info. Returns NULL if the current entry is | 199 // Returns the current entry info. Returns NULL if the current entry is |
184 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. | 200 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. |
185 EntryInfo* current_entry_info() const { | 201 EntryInfo* current_entry_info() const { |
186 return current_entry_info_.get(); | 202 return current_entry_info_.get(); |
187 } | 203 } |
188 | 204 |
189 // Returns the number of entries in the zip file. | 205 // Returns the number of entries in the zip file. |
190 // Open() must be called beforehand. | 206 // Open() must be called beforehand. |
191 int num_entries() const { return num_entries_; } | 207 int num_entries() const { return num_entries_; } |
192 | 208 |
(...skipping 18 matching lines...) Expand all Loading... | |
211 scoped_ptr<EntryInfo> current_entry_info_; | 227 scoped_ptr<EntryInfo> current_entry_info_; |
212 | 228 |
213 base::WeakPtrFactory<ZipReader> weak_ptr_factory_; | 229 base::WeakPtrFactory<ZipReader> weak_ptr_factory_; |
214 | 230 |
215 DISALLOW_COPY_AND_ASSIGN(ZipReader); | 231 DISALLOW_COPY_AND_ASSIGN(ZipReader); |
216 }; | 232 }; |
217 | 233 |
218 } // namespace zip | 234 } // namespace zip |
219 | 235 |
220 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 236 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
OLD | NEW |