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 <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" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 | 17 |
18 #if defined(USE_SYSTEM_MINIZIP) | 18 #if defined(USE_SYSTEM_MINIZIP) |
19 #include <minizip/unzip.h> | 19 #include <minizip/unzip.h> |
20 #else | 20 #else |
21 #include "third_party/zlib/contrib/minizip/unzip.h" | 21 #include "third_party/zlib/contrib/minizip/unzip.h" |
22 #endif | 22 #endif |
23 | 23 |
24 template <class T> class scoped_refptr; | |
25 | |
26 namespace base { | |
27 class RefCountedMemory; | |
28 } | |
29 | |
24 namespace zip { | 30 namespace zip { |
25 | 31 |
26 // This class is used for reading zip files. A typical use case of this | 32 // This class is used for reading zip files. A typical use case of this |
27 // class is to scan entries in a zip file and extract them. The code will | 33 // class is to scan entries in a zip file and extract them. The code will |
28 // look like: | 34 // look like: |
29 // | 35 // |
30 // ZipReader reader; | 36 // ZipReader reader; |
31 // reader.Open(zip_file_path); | 37 // reader.Open(zip_file_path); |
32 // while (reader.HasMore()) { | 38 // while (reader.HasMore()) { |
33 // reader.OpenCurrentEntryInZip(); | 39 // reader.OpenCurrentEntryInZip(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 // timestamp is not valid, the timestamp will be set to the current time. | 179 // timestamp is not valid, the timestamp will be set to the current time. |
174 bool ExtractCurrentEntryIntoDirectory( | 180 bool ExtractCurrentEntryIntoDirectory( |
175 const base::FilePath& output_directory_path); | 181 const base::FilePath& output_directory_path); |
176 | 182 |
177 #if defined(OS_POSIX) | 183 #if defined(OS_POSIX) |
178 // Extracts the current entry by writing directly to a file descriptor. | 184 // Extracts the current entry by writing directly to a file descriptor. |
179 // Does not close the file descriptor. Returns true on success. | 185 // Does not close the file descriptor. Returns true on success. |
180 bool ExtractCurrentEntryToFd(int fd); | 186 bool ExtractCurrentEntryToFd(int fd); |
181 #endif | 187 #endif |
182 | 188 |
189 // Extracts the current entry into memory. If the current file is a directory, | |
190 // NULL is stored in the |output| parameter. If the current file is a file, | |
191 // |output| is never set to NULL. Returns true on success. | |
192 // OpenCurrentEntryInZip() must be called beforehand. | |
193 // Note that EntryInfo::original_size() can return a different value than the | |
194 // real size of the uncompressed contents. Therefore, to prevent excessive | |
195 // memory usage, the maximum amount of data to read has to be specified in | |
196 // |max_read_bytes|. If the size of the uncompressed data is bigger than | |
197 // max_read_bytes then false is returned. |max_read_bytes| must be positive | |
198 // non-zero. | |
199 bool ExtractCurrentEntryToRefCountedMemory( | |
200 int max_read_bytes, | |
201 base::RefCountedMemory** output) const; | |
satorux1
2014/02/26 04:05:47
I found this API complex. RefCountedMemory is tric
João Eiras
2014/02/26 17:35:38
Tricky in what way ?
I'd have to warn that files
satorux1
2014/02/27 06:57:00
Reference counting in general is tricky. It makes
satorux1
2014/02/27 16:39:03
Maybe your concern was when the input data was big
| |
202 bool ExtractCurrentEntryToRefCountedMemory( | |
203 int max_read_bytes, | |
204 scoped_refptr<base::RefCountedMemory>* output) const; | |
satorux1
2014/02/26 04:05:47
scoped_refptr<> should only be used when an object
| |
205 | |
183 // Returns the current entry info. Returns NULL if the current entry is | 206 // Returns the current entry info. Returns NULL if the current entry is |
184 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. | 207 // not yet opened. OpenCurrentEntryInZip() must be called beforehand. |
185 EntryInfo* current_entry_info() const { | 208 EntryInfo* current_entry_info() const { |
186 return current_entry_info_.get(); | 209 return current_entry_info_.get(); |
187 } | 210 } |
188 | 211 |
189 // Returns the number of entries in the zip file. | 212 // Returns the number of entries in the zip file. |
190 // Open() must be called beforehand. | 213 // Open() must be called beforehand. |
191 int num_entries() const { return num_entries_; } | 214 int num_entries() const { return num_entries_; } |
192 | 215 |
(...skipping 18 matching lines...) Expand all Loading... | |
211 scoped_ptr<EntryInfo> current_entry_info_; | 234 scoped_ptr<EntryInfo> current_entry_info_; |
212 | 235 |
213 base::WeakPtrFactory<ZipReader> weak_ptr_factory_; | 236 base::WeakPtrFactory<ZipReader> weak_ptr_factory_; |
214 | 237 |
215 DISALLOW_COPY_AND_ASSIGN(ZipReader); | 238 DISALLOW_COPY_AND_ASSIGN(ZipReader); |
216 }; | 239 }; |
217 | 240 |
218 } // namespace zip | 241 } // namespace zip |
219 | 242 |
220 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 243 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
OLD | NEW |