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

Side by Side Diff: third_party/zlib/google/zip_reader.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 #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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 non-zero.
194 bool ExtractCurrentEntryToString(
195 size_t max_read_bytes,
196 std::string* output) const;
197
183 // Returns the current entry info. Returns NULL if the current entry is 198 // Returns the current entry info. Returns NULL if the current entry is
184 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. 199 // not yet opened. OpenCurrentEntryInZip() must be called beforehand.
185 EntryInfo* current_entry_info() const { 200 EntryInfo* current_entry_info() const {
186 return current_entry_info_.get(); 201 return current_entry_info_.get();
187 } 202 }
188 203
189 // Returns the number of entries in the zip file. 204 // Returns the number of entries in the zip file.
190 // Open() must be called beforehand. 205 // Open() must be called beforehand.
191 int num_entries() const { return num_entries_; } 206 int num_entries() const { return num_entries_; }
192 207
(...skipping 18 matching lines...) Expand all
211 scoped_ptr<EntryInfo> current_entry_info_; 226 scoped_ptr<EntryInfo> current_entry_info_;
212 227
213 base::WeakPtrFactory<ZipReader> weak_ptr_factory_; 228 base::WeakPtrFactory<ZipReader> weak_ptr_factory_;
214 229
215 DISALLOW_COPY_AND_ASSIGN(ZipReader); 230 DISALLOW_COPY_AND_ASSIGN(ZipReader);
216 }; 231 };
217 232
218 } // namespace zip 233 } // namespace zip
219 234
220 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ 235 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698