2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
20 * @brief This file is the header file of zip input
22 #ifndef DPL_ZIP_INPUT_H
23 #define DPL_ZIP_INPUT_H
25 #include <dpl/exception.h>
26 #include <dpl/noncopyable.h>
27 #include <dpl/abstract_input.h>
41 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
42 DECLARE_EXCEPTION_TYPE(Base, OpenFailed)
43 DECLARE_EXCEPTION_TYPE(Base, ReadGlobalInfoFailed)
44 DECLARE_EXCEPTION_TYPE(Base, ReadGlobalCommentFailed)
45 DECLARE_EXCEPTION_TYPE(Base, SeekFileFailed)
46 DECLARE_EXCEPTION_TYPE(Base, FileInfoFailed)
47 DECLARE_EXCEPTION_TYPE(Base, OpenFileFailed)
48 DECLARE_EXCEPTION_TYPE(Base, ReadFileFailed)
51 typedef std::pair<size_t, size_t> FileHandle;
55 unsigned int second; //< seconds after the minute - [0,59]
56 unsigned int minute; //< minutes after the hour - [0,59]
57 unsigned int hour; //< hours since midnight - [0,23]
58 unsigned int day; //< day of the month - [1,31]
59 unsigned int month; //< months since January - [0,11]
60 unsigned int year; //< years - [1980..2044]
72 FileDateTime(unsigned int secondArg,
73 unsigned int minuteArg,
76 unsigned int monthArg,
93 // File name and comment
98 unsigned long version; //< version made by
99 unsigned long versionNeeded; //< version needed to extract
100 unsigned long flag; //< general purpose bit flag
101 unsigned long compressionMethod; //< compression method
102 unsigned long dosDate; //< last mod file date in Dos fmt
103 unsigned long crc; //< crc-32
104 off64_t compressedSize; //< compressed size
105 off64_t uncompressedSize; //< uncompressed size
106 unsigned long diskNumberStart; //< disk number start
107 unsigned long internalFileAttributes; //< internal file attributes
108 unsigned long externalFileAttributes; //< external file attributes
110 FileDateTime dateTime;
119 compressionMethod(0),
125 internalFileAttributes(0),
126 externalFileAttributes(0),
131 FileInfo(const FileHandle &handleArg,
132 const std::string &nameArg,
133 const std::string &commentArg,
134 unsigned long versionArg,
135 unsigned long versionNeededArg,
136 unsigned long flagArg,
137 unsigned long compressionMethodArg,
138 unsigned long dosDateArg,
139 unsigned long crcArg,
140 const off64_t &compressedSizeArg,
141 const off64_t &uncompressedSizeArg,
142 unsigned long diskNumberStartArg,
143 unsigned long internalFileAttributesArg,
144 unsigned long externalFileAttributesArg,
145 const FileDateTime &dateTimeArg)
150 versionNeeded(versionNeededArg),
152 compressionMethod(compressionMethodArg),
155 compressedSize(compressedSizeArg),
156 uncompressedSize(uncompressedSizeArg),
157 diskNumberStart(diskNumberStartArg),
158 internalFileAttributes(internalFileAttributesArg),
159 externalFileAttributes(externalFileAttributesArg),
160 dateTime(dateTimeArg)
166 : public DPL::AbstractInput
171 friend class ZipInput;
172 File(class Device *device, FileHandle handle);
177 virtual DPL::BinaryQueueAutoPtr Read(size_t size);
181 class Device *m_device;
184 size_t m_numberOfFiles;
185 size_t m_globalCommentSize;
186 std::string m_globalComment;
188 // At least cache handles
189 typedef std::vector<FileInfo> FileInfoList;
190 FileInfoList m_fileInfos;
192 void ReadGlobalInfo(void *masterFile);
193 void ReadGlobalComment(void *masterFile);
194 void ReadInfos(void *masterFile);
197 typedef FileInfoList::const_iterator const_iterator;
198 typedef FileInfoList::const_reverse_iterator const_reverse_iterator;
199 typedef FileInfoList::size_type size_type;
203 * Open zip file from file
205 explicit ZipInput(const std::string &fileName);
213 const_iterator begin() const;
214 const_iterator end() const;
216 const_reverse_iterator rbegin() const;
217 const_reverse_iterator rend() const;
220 size_type size() const;
224 * Open a binary file for given file handle
226 * @return file object
227 * @param[in] handle Zip file handle to open
228 * @exception std::bad_alloc Cannot allocate memory to hold additional data
229 * @exception SteamOpenFailed Cannot find file with given handle
230 * @see BinaryQueue::BufferDeleterFree
232 File *OpenFile(FileHandle handle);
235 * Open a binary file for given file name
237 * @return file object
238 * @param[in] fileName Zip file name to open
239 * @exception std::bad_alloc Cannot allocate memory to hold additional data
240 * @exception SteamOpenFailed Cannot find file with given handle
241 * @see BinaryQueue::BufferDeleterFree
243 File *OpenFile(const std::string &fileName);
246 * Get archive global comment
248 * @return Global archive comment
250 const std::string &GetGlobalComment() const;
254 #endif // DPL_ZIP_INPUT_H