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 | 4 |
5 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 5 #ifndef THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
6 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 6 #define THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const unz_file_info& raw_file_info); | 50 const unz_file_info& raw_file_info); |
51 | 51 |
52 // Returns the file path. The path is usually relative like | 52 // Returns the file path. The path is usually relative like |
53 // "foo/bar.txt", but if it's absolute, is_unsafe() returns true. | 53 // "foo/bar.txt", but if it's absolute, is_unsafe() returns true. |
54 const base::FilePath& file_path() const { return file_path_; } | 54 const base::FilePath& file_path() const { return file_path_; } |
55 | 55 |
56 // Returns the size of the original file (i.e. after uncompressed). | 56 // Returns the size of the original file (i.e. after uncompressed). |
57 // Returns 0 if the entry is a directory. | 57 // Returns 0 if the entry is a directory. |
58 int64 original_size() const { return original_size_; } | 58 int64 original_size() const { return original_size_; } |
59 | 59 |
60 // Returns the last modified time. | 60 // Returns the last modified time. If the time stored in the zip file was |
| 61 // not valid, the unix epoch will be returned. |
| 62 // |
| 63 // The time stored in the zip archive uses the MS-DOS date and time format. |
| 64 // http://msdn.microsoft.com/en-us/library/ms724247(v=vs.85).aspx |
| 65 // As such the following limitations apply: |
| 66 // * only years from 1980 to 2107 can be represented. |
| 67 // * the time stamp has a 2 second resolution. |
| 68 // * there's no timezone information, so the time is interpreted as local. |
61 base::Time last_modified() const { return last_modified_; } | 69 base::Time last_modified() const { return last_modified_; } |
62 | 70 |
63 // Returns true if the entry is a directory. | 71 // Returns true if the entry is a directory. |
64 bool is_directory() const { return is_directory_; } | 72 bool is_directory() const { return is_directory_; } |
65 | 73 |
66 // Returns true if the entry is unsafe, like having ".." or invalid | 74 // Returns true if the entry is unsafe, like having ".." or invalid |
67 // UTF-8 characters in its file name, or the file path is absolute. | 75 // UTF-8 characters in its file name, or the file path is absolute. |
68 bool is_unsafe() const { return is_unsafe_; } | 76 bool is_unsafe() const { return is_unsafe_; } |
69 | 77 |
70 private: | 78 private: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // Locates an entry in the zip file and opens it. Returns true on | 128 // Locates an entry in the zip file and opens it. Returns true on |
121 // success. This function internally calls OpenCurrentEntryInZip() on | 129 // success. This function internally calls OpenCurrentEntryInZip() on |
122 // success. On failure, current_entry_info() becomes NULL. | 130 // success. On failure, current_entry_info() becomes NULL. |
123 bool LocateAndOpenEntry(const base::FilePath& path_in_zip); | 131 bool LocateAndOpenEntry(const base::FilePath& path_in_zip); |
124 | 132 |
125 // Extracts the current entry to the given output file path. If the | 133 // Extracts the current entry to the given output file path. If the |
126 // current file is a directory, just creates a directory | 134 // current file is a directory, just creates a directory |
127 // instead. Returns true on success. OpenCurrentEntryInZip() must be | 135 // instead. Returns true on success. OpenCurrentEntryInZip() must be |
128 // called beforehand. | 136 // called beforehand. |
129 // | 137 // |
130 // This function does not preserve the timestamp of the original entry. | 138 // This function preserves the timestamp of the original entry. If that |
| 139 // timestamp is not valid, the timestamp will be set to the current time. |
131 bool ExtractCurrentEntryToFilePath(const base::FilePath& output_file_path); | 140 bool ExtractCurrentEntryToFilePath(const base::FilePath& output_file_path); |
132 | 141 |
133 // Extracts the current entry to the given output directory path using | 142 // Extracts the current entry to the given output directory path using |
134 // ExtractCurrentEntryToFilePath(). Sub directories are created as needed | 143 // ExtractCurrentEntryToFilePath(). Sub directories are created as needed |
135 // based on the file path of the current entry. For example, if the file | 144 // based on the file path of the current entry. For example, if the file |
136 // path in zip is "foo/bar.txt", and the output directory is "output", | 145 // path in zip is "foo/bar.txt", and the output directory is "output", |
137 // "output/foo/bar.txt" will be created. | 146 // "output/foo/bar.txt" will be created. |
138 // | 147 // |
139 // Returns true on success. OpenCurrentEntryInZip() must be called | 148 // Returns true on success. OpenCurrentEntryInZip() must be called |
140 // beforehand. | 149 // beforehand. |
| 150 // |
| 151 // This function preserves the timestamp of the original entry. If that |
| 152 // timestamp is not valid, the timestamp will be set to the current time. |
141 bool ExtractCurrentEntryIntoDirectory( | 153 bool ExtractCurrentEntryIntoDirectory( |
142 const base::FilePath& output_directory_path); | 154 const base::FilePath& output_directory_path); |
143 | 155 |
144 #if defined(OS_POSIX) | 156 #if defined(OS_POSIX) |
145 // Extracts the current entry by writing directly to a file descriptor. | 157 // Extracts the current entry by writing directly to a file descriptor. |
146 // Does not close the file descriptor. Returns true on success. | 158 // Does not close the file descriptor. Returns true on success. |
147 bool ExtractCurrentEntryToFd(int fd); | 159 bool ExtractCurrentEntryToFd(int fd); |
148 #endif | 160 #endif |
149 | 161 |
150 // Returns the current entry info. Returns NULL if the current entry is | 162 // Returns the current entry info. Returns NULL if the current entry is |
(...skipping 17 matching lines...) Expand all Loading... |
168 int num_entries_; | 180 int num_entries_; |
169 bool reached_end_; | 181 bool reached_end_; |
170 scoped_ptr<EntryInfo> current_entry_info_; | 182 scoped_ptr<EntryInfo> current_entry_info_; |
171 | 183 |
172 DISALLOW_COPY_AND_ASSIGN(ZipReader); | 184 DISALLOW_COPY_AND_ASSIGN(ZipReader); |
173 }; | 185 }; |
174 | 186 |
175 } // namespace zip | 187 } // namespace zip |
176 | 188 |
177 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ | 189 #endif // THIRD_PARTY_ZLIB_GOOGLE_ZIP_READER_H_ |
OLD | NEW |