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

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

Issue 2961373002: Improve Zip File Scanning on Mac (Closed)
Patch Set: refactoring in zip_reader Created 3 years, 5 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // 152 //
153 // Note that there is no CloseCurrentEntryInZip(). The the current entry 153 // Note that there is no CloseCurrentEntryInZip(). The the current entry
154 // state is reset automatically as needed. 154 // state is reset automatically as needed.
155 bool OpenCurrentEntryInZip(); 155 bool OpenCurrentEntryInZip();
156 156
157 // Locates an entry in the zip file and opens it. Returns true on 157 // Locates an entry in the zip file and opens it. Returns true on
158 // success. This function internally calls OpenCurrentEntryInZip() on 158 // success. This function internally calls OpenCurrentEntryInZip() on
159 // success. On failure, current_entry_info() becomes NULL. 159 // success. On failure, current_entry_info() becomes NULL.
160 bool LocateAndOpenEntry(const base::FilePath& path_in_zip); 160 bool LocateAndOpenEntry(const base::FilePath& path_in_zip);
161 161
162 // Extracts the current entry in chunks to |delegate|. 162 // Extracts entirety of the current entry in chunks to |delegate|.
satorux1 2017/07/21 05:27:02 While you are at it, could you add documentation a
mortonm 2017/07/21 16:29:56 Done. Didn't add an explanation here, but there ar
163 bool ExtractCurrentEntry(WriterDelegate* delegate) const; 163 bool ExtractCurrentEntry(WriterDelegate* delegate) const;
164 164
165 // Extracts |num_bytes_to_extract| bytes of the current entry to |delegate|,
166 // starting from the beginning of the entry. A negative value for
167 // |num_bytes_to_extract| means the entire current entry will be extracted.
168 // Returns false if |num_bytes_to_extract| is greater than file length.
169 bool ExtractFromBeginningOfCurrentEntry(WriterDelegate* delegate,
170 int64_t num_bytes_to_extract) const;
171
165 // Extracts the current entry to the given output file path. If the 172 // Extracts the current entry to the given output file path. If the
166 // current file is a directory, just creates a directory 173 // current file is a directory, just creates a directory
167 // instead. Returns true on success. OpenCurrentEntryInZip() must be 174 // instead. Returns true on success. OpenCurrentEntryInZip() must be
168 // called beforehand. 175 // called beforehand.
169 // 176 //
170 // This function preserves the timestamp of the original entry. If that 177 // This function preserves the timestamp of the original entry. If that
171 // timestamp is not valid, the timestamp will be set to the current time. 178 // timestamp is not valid, the timestamp will be set to the current time.
172 bool ExtractCurrentEntryToFilePath( 179 bool ExtractCurrentEntryToFilePath(
173 const base::FilePath& output_file_path) const; 180 const base::FilePath& output_file_path) const;
174 181
(...skipping 20 matching lines...) Expand all
195 // 202 //
196 // This function preserves the timestamp of the original entry. If that 203 // This function preserves the timestamp of the original entry. If that
197 // timestamp is not valid, the timestamp will be set to the current time. 204 // timestamp is not valid, the timestamp will be set to the current time.
198 bool ExtractCurrentEntryIntoDirectory( 205 bool ExtractCurrentEntryIntoDirectory(
199 const base::FilePath& output_directory_path) const; 206 const base::FilePath& output_directory_path) const;
200 207
201 // Extracts the current entry by writing directly to a platform file. 208 // Extracts the current entry by writing directly to a platform file.
202 // Does not close the file. Returns true on success. 209 // Does not close the file. Returns true on success.
203 bool ExtractCurrentEntryToFile(base::File* file) const; 210 bool ExtractCurrentEntryToFile(base::File* file) const;
204 211
205 // Extracts the current entry into memory. If the current entry is a directory 212 // Extracts the current entry into memory. If the current entry is a
206 // the |output| parameter is set to the empty string. If the current entry is 213 // directory, the |output| parameter is set to the empty string. If the
207 // a file, the |output| parameter is filled with its contents. Returns true on 214 // current entry is a file, the |output| parameter is filled with its
208 // success. OpenCurrentEntryInZip() must be called beforehand. 215 // contents. Returns true on success. OpenCurrentEntryInZip() must be called
209 // Note: the |output| parameter can be filled with a big amount of data, avoid 216 // beforehand. Note: the |output| parameter can be filled with a big amount of
210 // passing it around by value, but by reference or pointer. 217 // data, avoid passing it around by value, but by reference or pointer. Note:
211 // Note: the value returned by EntryInfo::original_size() cannot be 218 // the value returned by EntryInfo::original_size() cannot be trusted, so the
212 // trusted, so the real size of the uncompressed contents can be different. 219 // real size of the uncompressed contents can be different. Use
213 // Use max_read_bytes to limit the ammount of memory used to carry the entry. 220 // |max_read_bytes| to limit the ammount of memory used to carry the entry. If
214 // If the real size of the uncompressed data is bigger than max_read_bytes 221 // the real size of the uncompressed data is bigger than |max_read_bytes| then
215 // then false is returned. |max_read_bytes| must be non-zero. 222 // false is returned. |max_read_bytes| must be non-zero.
216 bool ExtractCurrentEntryToString( 223 bool ExtractCurrentEntryToString(
217 size_t max_read_bytes, 224 size_t max_read_bytes,
218 std::string* output) const; 225 std::string* output) const;
219 226
227 // Same as ExtractCurrentEntryToString(), except specifies the number of bytes
228 // to read into the string so that it is possible to only read a partial
229 // amount of the entry into a string. If
230 // |read_entire_file|, returns true only if |num_bytes_to_extract| is at least
231 // the size of entire file.
232 bool ExtractFromBeginningOfCurrentEntryToString(size_t num_bytes_to_extract,
233 bool read_entire_file,
234 std::string* output) const;
235
220 // Returns the current entry info. Returns NULL if the current entry is 236 // Returns the current entry info. Returns NULL if the current entry is
221 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. 237 // not yet opened. OpenCurrentEntryInZip() must be called beforehand.
222 EntryInfo* current_entry_info() const { 238 EntryInfo* current_entry_info() const {
223 return current_entry_info_.get(); 239 return current_entry_info_.get();
224 } 240 }
225 241
226 // Returns the number of entries in the zip file. 242 // Returns the number of entries in the zip file.
227 // Open() must be called beforehand. 243 // Open() must be called beforehand.
228 int num_entries() const { return num_entries_; } 244 int num_entries() const { return num_entries_; }
229 245
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 private: 288 private:
273 base::File* file_; 289 base::File* file_;
274 int64_t file_length_; 290 int64_t file_length_;
275 291
276 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); 292 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate);
277 }; 293 };
278 294
279 } // namespace zip 295 } // namespace zip
280 296
281 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ 297 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698