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>
40 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
41 DECLARE_EXCEPTION_TYPE(Base, OpenFailed)
42 DECLARE_EXCEPTION_TYPE(Base, ReadGlobalInfoFailed)
43 DECLARE_EXCEPTION_TYPE(Base, ReadGlobalCommentFailed)
44 DECLARE_EXCEPTION_TYPE(Base, SeekFileFailed)
45 DECLARE_EXCEPTION_TYPE(Base, FileInfoFailed)
46 DECLARE_EXCEPTION_TYPE(Base, OpenFileFailed)
47 DECLARE_EXCEPTION_TYPE(Base, ReadFileFailed)
50 typedef std::pair<size_t, size_t> FileHandle;
57 // File name and comment
62 off64_t compressedSize; //< compressed size
63 off64_t uncompressedSize; //< uncompressed size
73 FileInfo(const FileHandle &handleArg,
74 const std::string &nameArg,
75 const std::string &commentArg,
76 const off64_t &compressedSizeArg,
77 const off64_t &uncompressedSizeArg) :
81 compressedSize(compressedSizeArg),
82 uncompressedSize(uncompressedSizeArg)
87 public DPL::AbstractInput
92 friend class ZipInput;
93 File(class Device *device, FileHandle handle);
98 virtual DPL::BinaryQueueAutoPtr Read(size_t size);
102 class Device * m_device;
105 size_t m_numberOfFiles;
106 size_t m_globalCommentSize;
107 std::string m_globalComment;
109 // At least cache handles
110 typedef std::vector<FileInfo> FileInfoList;
111 FileInfoList m_fileInfos;
113 void ReadGlobalInfo(void *masterFile);
114 void ReadGlobalComment(void *masterFile);
115 void ReadInfos(void *masterFile);
118 typedef FileInfoList::const_iterator const_iterator;
119 typedef FileInfoList::const_reverse_iterator const_reverse_iterator;
120 typedef FileInfoList::size_type size_type;
124 * Open zip file from file
126 explicit ZipInput(const std::string &fileName);
134 const_iterator begin() const;
135 const_iterator end() const;
137 const_reverse_iterator rbegin() const;
138 const_reverse_iterator rend() const;
141 size_type size() const;
145 * Open a binary file for given file name
147 * @return file object
148 * @param[in] fileName Zip file name to open
149 * @exception std::bad_alloc Cannot allocate memory to hold additional data
150 * @exception SteamOpenFailed Cannot find file with given handle
151 * @see BinaryQueue::BufferDeleterFree
153 File *OpenFile(const std::string &fileName);
156 * Get archive global comment
158 * @return Global archive comment
160 const std::string &GetGlobalComment() const;
164 #endif // DPL_ZIP_INPUT_H