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

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

Issue 292443006: New ZipReader::ExtractCurrentEntryToString API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src
Patch Set: rebase Created 6 years, 6 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
« no previous file with comments | « no previous file | third_party/zlib/google/zip_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // timestamp is not valid, the timestamp will be set to the current time. 175 // timestamp is not valid, the timestamp will be set to the current time.
176 bool ExtractCurrentEntryIntoDirectory( 176 bool ExtractCurrentEntryIntoDirectory(
177 const base::FilePath& output_directory_path); 177 const base::FilePath& output_directory_path);
178 178
179 #if defined(OS_POSIX) 179 #if defined(OS_POSIX)
180 // Extracts the current entry by writing directly to a file descriptor. 180 // Extracts the current entry by writing directly to a file descriptor.
181 // Does not close the file descriptor. Returns true on success. 181 // Does not close the file descriptor. Returns true on success.
182 bool ExtractCurrentEntryToFd(int fd); 182 bool ExtractCurrentEntryToFd(int fd);
183 #endif 183 #endif
184 184
185 // Extracts the current entry into memory. If the current entry is a directory
186 // the |output| parameter is set to the empty string. If the current entry is
187 // a file, the |output| parameter is filled with its contents. Returns true on
188 // success. OpenCurrentEntryInZip() must be called beforehand.
189 // Note: the |output| parameter can be filled with a big amount of data, avoid
190 // passing it around by value, but by reference or pointer.
191 // Note: the value returned by EntryInfo::original_size() cannot be
192 // trusted, so the real size of the uncompressed contents can be different.
193 // Use max_read_bytes to limit the ammount of memory used to carry the entry.
194 // If the real size of the uncompressed data is bigger than max_read_bytes
195 // then false is returned. |max_read_bytes| must be non-zero.
196 bool ExtractCurrentEntryToString(
197 size_t max_read_bytes,
198 std::string* output) const;
199
185 // Returns the current entry info. Returns NULL if the current entry is 200 // Returns the current entry info. Returns NULL if the current entry is
186 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. 201 // not yet opened. OpenCurrentEntryInZip() must be called beforehand.
187 EntryInfo* current_entry_info() const { 202 EntryInfo* current_entry_info() const {
188 return current_entry_info_.get(); 203 return current_entry_info_.get();
189 } 204 }
190 205
191 // Returns the number of entries in the zip file. 206 // Returns the number of entries in the zip file.
192 // Open() must be called beforehand. 207 // Open() must be called beforehand.
193 int num_entries() const { return num_entries_; } 208 int num_entries() const { return num_entries_; }
194 209
(...skipping 18 matching lines...) Expand all
213 scoped_ptr<EntryInfo> current_entry_info_; 228 scoped_ptr<EntryInfo> current_entry_info_;
214 229
215 base::WeakPtrFactory<ZipReader> weak_ptr_factory_; 230 base::WeakPtrFactory<ZipReader> weak_ptr_factory_;
216 231
217 DISALLOW_COPY_AND_ASSIGN(ZipReader); 232 DISALLOW_COPY_AND_ASSIGN(ZipReader);
218 }; 233 };
219 234
220 } // namespace zip 235 } // namespace zip
221 236
222 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ 237 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_
OLDNEW
« no previous file with comments | « no previous file | third_party/zlib/google/zip_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698