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 <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 Loading... |
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 |num_bytes_to_extract| bytes of the current entry to |delegate|, |
163 bool ExtractCurrentEntry(WriterDelegate* delegate) const; | 163 // starting from the beginning of the entry. Return value specifies whether |
| 164 // the entire file was extracted. |
| 165 bool ExtractCurrentEntry(WriterDelegate* delegate, |
| 166 uint64_t num_bytes_to_extract) const; |
164 | 167 |
165 // Extracts the current entry to the given output file path. If the | 168 // Extracts the current entry to the given output file path. If the |
166 // current file is a directory, just creates a directory | 169 // current file is a directory, just creates a directory |
167 // instead. Returns true on success. OpenCurrentEntryInZip() must be | 170 // instead. Returns true on success. OpenCurrentEntryInZip() must be |
168 // called beforehand. | 171 // called beforehand. |
169 // | 172 // |
170 // This function preserves the timestamp of the original entry. If that | 173 // 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. | 174 // timestamp is not valid, the timestamp will be set to the current time. |
172 bool ExtractCurrentEntryToFilePath( | 175 bool ExtractCurrentEntryToFilePath( |
173 const base::FilePath& output_file_path) const; | 176 const base::FilePath& output_file_path) const; |
(...skipping 21 matching lines...) Expand all Loading... |
195 // | 198 // |
196 // This function preserves the timestamp of the original entry. If that | 199 // 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. | 200 // timestamp is not valid, the timestamp will be set to the current time. |
198 bool ExtractCurrentEntryIntoDirectory( | 201 bool ExtractCurrentEntryIntoDirectory( |
199 const base::FilePath& output_directory_path) const; | 202 const base::FilePath& output_directory_path) const; |
200 | 203 |
201 // Extracts the current entry by writing directly to a platform file. | 204 // Extracts the current entry by writing directly to a platform file. |
202 // Does not close the file. Returns true on success. | 205 // Does not close the file. Returns true on success. |
203 bool ExtractCurrentEntryToFile(base::File* file) const; | 206 bool ExtractCurrentEntryToFile(base::File* file) const; |
204 | 207 |
205 // Extracts the current entry into memory. If the current entry is a directory | 208 // 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 | 209 // 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 | 210 // current entry is a file, the |output| parameter is filled with its |
208 // success. OpenCurrentEntryInZip() must be called beforehand. | 211 // contents. OpenCurrentEntryInZip() must be called beforehand. Note: the |
209 // Note: the |output| parameter can be filled with a big amount of data, avoid | 212 // |output| parameter can be filled with a big amount of data, avoid passing |
210 // passing it around by value, but by reference or pointer. | 213 // it around by value, but by reference or pointer. Note: the value returned |
211 // Note: the value returned by EntryInfo::original_size() cannot be | 214 // by EntryInfo::original_size() cannot be trusted, so the real size of the |
212 // trusted, so the real size of the uncompressed contents can be different. | 215 // uncompressed contents can be different. |max_read_bytes| limits the ammount |
213 // Use max_read_bytes to limit the ammount of memory used to carry the entry. | 216 // of memory used to carry the entry. Returns true if the entire content is |
214 // If the real size of the uncompressed data is bigger than max_read_bytes | 217 // read. If the entry is bigger than |max_read_bytes|, returns false and |
215 // then false is returned. |max_read_bytes| must be non-zero. | 218 // |output| is filled with |max_read_bytes| of data. If an error occurs, |
216 bool ExtractCurrentEntryToString( | 219 // returns false, and |output| is set to the empty string. |
217 size_t max_read_bytes, | 220 bool ExtractCurrentEntryToString(uint64_t max_read_bytes, |
218 std::string* output) const; | 221 std::string* output) const; |
219 | 222 |
220 // Returns the current entry info. Returns NULL if the current entry is | 223 // Returns the current entry info. Returns NULL if the current entry is |
221 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. | 224 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. |
222 EntryInfo* current_entry_info() const { | 225 EntryInfo* current_entry_info() const { |
223 return current_entry_info_.get(); | 226 return current_entry_info_.get(); |
224 } | 227 } |
225 | 228 |
226 // Returns the number of entries in the zip file. | 229 // Returns the number of entries in the zip file. |
227 // Open() must be called beforehand. | 230 // Open() must be called beforehand. |
228 int num_entries() const { return num_entries_; } | 231 int num_entries() const { return num_entries_; } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 private: | 275 private: |
273 base::File* file_; | 276 base::File* file_; |
274 int64_t file_length_; | 277 int64_t file_length_; |
275 | 278 |
276 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); | 279 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); |
277 }; | 280 }; |
278 | 281 |
279 } // namespace zip | 282 } // namespace zip |
280 | 283 |
281 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 284 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
OLD | NEW |