Chromium Code Reviews| 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. A negative value for |
| 164 // |num_bytes_to_extract| means the entire current entry will be extracted. | |
| 165 // Returns false if file is too large to be extracted to |delegate| or if file | |
| 166 // is too small to fill |num_bytes_to_extract|. | |
| 167 bool ExtractCurrentEntry(WriterDelegate* delegate, | |
| 168 int64_t num_bytes_to_extract) const; | |
| 164 | 169 |
| 165 // Extracts the current entry to the given output file path. If the | 170 // Extracts the current entry to the given output file path. If the |
| 166 // current file is a directory, just creates a directory | 171 // current file is a directory, just creates a directory |
| 167 // instead. Returns true on success. OpenCurrentEntryInZip() must be | 172 // instead. Returns true on success. OpenCurrentEntryInZip() must be |
| 168 // called beforehand. | 173 // called beforehand. |
| 169 // | 174 // |
| 170 // This function preserves the timestamp of the original entry. If that | 175 // 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. | 176 // timestamp is not valid, the timestamp will be set to the current time. |
| 172 bool ExtractCurrentEntryToFilePath( | 177 bool ExtractCurrentEntryToFilePath( |
| 173 const base::FilePath& output_file_path) const; | 178 const base::FilePath& output_file_path) const; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 195 // | 200 // |
| 196 // This function preserves the timestamp of the original entry. If that | 201 // 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. | 202 // timestamp is not valid, the timestamp will be set to the current time. |
| 198 bool ExtractCurrentEntryIntoDirectory( | 203 bool ExtractCurrentEntryIntoDirectory( |
| 199 const base::FilePath& output_directory_path) const; | 204 const base::FilePath& output_directory_path) const; |
| 200 | 205 |
| 201 // Extracts the current entry by writing directly to a platform file. | 206 // Extracts the current entry by writing directly to a platform file. |
| 202 // Does not close the file. Returns true on success. | 207 // Does not close the file. Returns true on success. |
| 203 bool ExtractCurrentEntryToFile(base::File* file) const; | 208 bool ExtractCurrentEntryToFile(base::File* file) const; |
| 204 | 209 |
| 205 // Extracts the current entry into memory. If the current entry is a directory | 210 // 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 | 211 // 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 | 212 // current entry is a file, the |output| parameter is filled with its |
| 208 // success. OpenCurrentEntryInZip() must be called beforehand. | 213 // contents. OpenCurrentEntryInZip() must be called beforehand. Note: the |
| 209 // Note: the |output| parameter can be filled with a big amount of data, avoid | 214 // |output| parameter can be filled with a big amount of data, avoid passing |
| 210 // passing it around by value, but by reference or pointer. | 215 // it around by value, but by reference or pointer. Note: the value returned |
| 211 // Note: the value returned by EntryInfo::original_size() cannot be | 216 // 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. | 217 // uncompressed contents can be different. If |read_entire_file| is true, then |
| 213 // Use max_read_bytes to limit the ammount of memory used to carry the entry. | 218 // |num_bytes| limits the ammount of memory used to carry the entry, and false |
| 214 // If the real size of the uncompressed data is bigger than max_read_bytes | 219 // is returned if the real size of the uncompressed data is bigger than |
| 215 // then false is returned. |max_read_bytes| must be non-zero. | 220 // |max_read_bytes|. Otherwise if |read_entire_file| is false, |num_bytes| |
|
satorux1
2017/07/25 07:55:15
nit: num_bytes and max_read_bytes are not consiste
mortonm
2017/07/25 18:10:15
Done.
| |
| 216 bool ExtractCurrentEntryToString( | 221 // signifies the number of bytes to read from the file, and false is returned |
| 217 size_t max_read_bytes, | 222 // if the real size of the uncompressed data is smaller than |max_read_bytes|. |
| 218 std::string* output) const; | 223 bool ExtractCurrentEntryToString(size_t num_bytes, |
| 224 bool read_entire_file, | |
|
satorux1
2017/07/25 07:55:15
zip_analyzier is the only caller of this function,
mortonm
2017/07/25 18:10:15
Done, I agree, this is a better way of writing thi
| |
| 225 std::string* output) const; | |
| 219 | 226 |
| 220 // Returns the current entry info. Returns NULL if the current entry is | 227 // Returns the current entry info. Returns NULL if the current entry is |
| 221 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. | 228 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. |
| 222 EntryInfo* current_entry_info() const { | 229 EntryInfo* current_entry_info() const { |
| 223 return current_entry_info_.get(); | 230 return current_entry_info_.get(); |
| 224 } | 231 } |
| 225 | 232 |
| 226 // Returns the number of entries in the zip file. | 233 // Returns the number of entries in the zip file. |
| 227 // Open() must be called beforehand. | 234 // Open() must be called beforehand. |
| 228 int num_entries() const { return num_entries_; } | 235 int num_entries() const { return num_entries_; } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 private: | 279 private: |
| 273 base::File* file_; | 280 base::File* file_; |
| 274 int64_t file_length_; | 281 int64_t file_length_; |
| 275 | 282 |
| 276 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); | 283 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); |
| 277 }; | 284 }; |
| 278 | 285 |
| 279 } // namespace zip | 286 } // namespace zip |
| 280 | 287 |
| 281 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 288 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
| OLD | NEW |