| 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> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <string> | 10 #include <string> |
| 8 | 11 |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/callback.h" | 12 #include "base/callback.h" |
| 11 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 12 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/macros.h" |
| 14 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 16 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 17 | 20 |
| 18 #if defined(USE_SYSTEM_MINIZIP) | 21 #if defined(USE_SYSTEM_MINIZIP) |
| 19 #include <minizip/unzip.h> | 22 #include <minizip/unzip.h> |
| 20 #else | 23 #else |
| 21 #include "third_party/zlib/contrib/minizip/unzip.h" | 24 #include "third_party/zlib/contrib/minizip/unzip.h" |
| 22 #endif | 25 #endif |
| 23 | 26 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // using LocateAndOpenEntry(). | 60 // using LocateAndOpenEntry(). |
| 58 // | 61 // |
| 59 class ZipReader { | 62 class ZipReader { |
| 60 public: | 63 public: |
| 61 // A callback that is called when the operation is successful. | 64 // A callback that is called when the operation is successful. |
| 62 typedef base::Closure SuccessCallback; | 65 typedef base::Closure SuccessCallback; |
| 63 // A callback that is called when the operation fails. | 66 // A callback that is called when the operation fails. |
| 64 typedef base::Closure FailureCallback; | 67 typedef base::Closure FailureCallback; |
| 65 // A callback that is called periodically during the operation with the number | 68 // A callback that is called periodically during the operation with the number |
| 66 // of bytes that have been processed so far. | 69 // of bytes that have been processed so far. |
| 67 typedef base::Callback<void(int64)> ProgressCallback; | 70 typedef base::Callback<void(int64_t)> ProgressCallback; |
| 68 | 71 |
| 69 // This class represents information of an entry (file or directory) in | 72 // This class represents information of an entry (file or directory) in |
| 70 // a zip file. | 73 // a zip file. |
| 71 class EntryInfo { | 74 class EntryInfo { |
| 72 public: | 75 public: |
| 73 EntryInfo(const std::string& filename_in_zip, | 76 EntryInfo(const std::string& filename_in_zip, |
| 74 const unz_file_info& raw_file_info); | 77 const unz_file_info& raw_file_info); |
| 75 | 78 |
| 76 // Returns the file path. The path is usually relative like | 79 // Returns the file path. The path is usually relative like |
| 77 // "foo/bar.txt", but if it's absolute, is_unsafe() returns true. | 80 // "foo/bar.txt", but if it's absolute, is_unsafe() returns true. |
| 78 const base::FilePath& file_path() const { return file_path_; } | 81 const base::FilePath& file_path() const { return file_path_; } |
| 79 | 82 |
| 80 // Returns the size of the original file (i.e. after uncompressed). | 83 // Returns the size of the original file (i.e. after uncompressed). |
| 81 // Returns 0 if the entry is a directory. | 84 // Returns 0 if the entry is a directory. |
| 82 // Note: this value should not be trusted, because it is stored as metadata | 85 // Note: this value should not be trusted, because it is stored as metadata |
| 83 // in the zip archive and can be different from the real uncompressed size. | 86 // in the zip archive and can be different from the real uncompressed size. |
| 84 int64 original_size() const { return original_size_; } | 87 int64_t original_size() const { return original_size_; } |
| 85 | 88 |
| 86 // Returns the last modified time. If the time stored in the zip file was | 89 // Returns the last modified time. If the time stored in the zip file was |
| 87 // not valid, the unix epoch will be returned. | 90 // not valid, the unix epoch will be returned. |
| 88 // | 91 // |
| 89 // The time stored in the zip archive uses the MS-DOS date and time format. | 92 // The time stored in the zip archive uses the MS-DOS date and time format. |
| 90 // http://msdn.microsoft.com/en-us/library/ms724247(v=vs.85).aspx | 93 // http://msdn.microsoft.com/en-us/library/ms724247(v=vs.85).aspx |
| 91 // As such the following limitations apply: | 94 // As such the following limitations apply: |
| 92 // * only years from 1980 to 2107 can be represented. | 95 // * only years from 1980 to 2107 can be represented. |
| 93 // * the time stamp has a 2 second resolution. | 96 // * the time stamp has a 2 second resolution. |
| 94 // * there's no timezone information, so the time is interpreted as local. | 97 // * there's no timezone information, so the time is interpreted as local. |
| 95 base::Time last_modified() const { return last_modified_; } | 98 base::Time last_modified() const { return last_modified_; } |
| 96 | 99 |
| 97 // Returns true if the entry is a directory. | 100 // Returns true if the entry is a directory. |
| 98 bool is_directory() const { return is_directory_; } | 101 bool is_directory() const { return is_directory_; } |
| 99 | 102 |
| 100 // Returns true if the entry is unsafe, like having ".." or invalid | 103 // Returns true if the entry is unsafe, like having ".." or invalid |
| 101 // UTF-8 characters in its file name, or the file path is absolute. | 104 // UTF-8 characters in its file name, or the file path is absolute. |
| 102 bool is_unsafe() const { return is_unsafe_; } | 105 bool is_unsafe() const { return is_unsafe_; } |
| 103 | 106 |
| 104 private: | 107 private: |
| 105 const base::FilePath file_path_; | 108 const base::FilePath file_path_; |
| 106 int64 original_size_; | 109 int64_t original_size_; |
| 107 base::Time last_modified_; | 110 base::Time last_modified_; |
| 108 bool is_directory_; | 111 bool is_directory_; |
| 109 bool is_unsafe_; | 112 bool is_unsafe_; |
| 110 DISALLOW_COPY_AND_ASSIGN(EntryInfo); | 113 DISALLOW_COPY_AND_ASSIGN(EntryInfo); |
| 111 }; | 114 }; |
| 112 | 115 |
| 113 ZipReader(); | 116 ZipReader(); |
| 114 ~ZipReader(); | 117 ~ZipReader(); |
| 115 | 118 |
| 116 // Opens the zip file specified by |zip_file_path|. Returns true on | 119 // Opens the zip file specified by |zip_file_path|. Returns true on |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 233 |
| 231 // Resets the internal state. | 234 // Resets the internal state. |
| 232 void Reset(); | 235 void Reset(); |
| 233 | 236 |
| 234 // Extracts a chunk of the file to the target. Will post a task for the next | 237 // Extracts a chunk of the file to the target. Will post a task for the next |
| 235 // chunk and success/failure/progress callbacks as necessary. | 238 // chunk and success/failure/progress callbacks as necessary. |
| 236 void ExtractChunk(base::File target_file, | 239 void ExtractChunk(base::File target_file, |
| 237 const SuccessCallback& success_callback, | 240 const SuccessCallback& success_callback, |
| 238 const FailureCallback& failure_callback, | 241 const FailureCallback& failure_callback, |
| 239 const ProgressCallback& progress_callback, | 242 const ProgressCallback& progress_callback, |
| 240 const int64 offset); | 243 const int64_t offset); |
| 241 | 244 |
| 242 unzFile zip_file_; | 245 unzFile zip_file_; |
| 243 int num_entries_; | 246 int num_entries_; |
| 244 bool reached_end_; | 247 bool reached_end_; |
| 245 scoped_ptr<EntryInfo> current_entry_info_; | 248 scoped_ptr<EntryInfo> current_entry_info_; |
| 246 | 249 |
| 247 base::WeakPtrFactory<ZipReader> weak_ptr_factory_; | 250 base::WeakPtrFactory<ZipReader> weak_ptr_factory_; |
| 248 | 251 |
| 249 DISALLOW_COPY_AND_ASSIGN(ZipReader); | 252 DISALLOW_COPY_AND_ASSIGN(ZipReader); |
| 250 }; | 253 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 269 private: | 272 private: |
| 270 base::File* file_; | 273 base::File* file_; |
| 271 int64_t file_length_; | 274 int64_t file_length_; |
| 272 | 275 |
| 273 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); | 276 DISALLOW_COPY_AND_ASSIGN(FileWriterDelegate); |
| 274 }; | 277 }; |
| 275 | 278 |
| 276 } // namespace zip | 279 } // namespace zip |
| 277 | 280 |
| 278 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 281 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
| OLD | NEW |