]> git.donarmstrong.com Git - flightcrew.git/blob - src/zipios/zipios++/zipfile.h
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / zipios / zipios++ / zipfile.h
1 #ifndef ZIPFILE_H
2 #define ZIPFILE_H
3
4 #include "zipios++/zipios-config.h"
5
6 #include <vector>
7 #include "zipios++/meta-iostreams.h"
8
9 #include "zipios++/fcoll.h"
10 #include "zipios++/ziphead.h"
11 #include "zipios++/virtualseeker.h"
12 #include "../../FlightCrew/Misc/BoostFilesystemUse.h"
13
14 namespace zipios {
15
16 using std::ifstream ;
17
18 /** \anchor zipfile_anchor
19     ZipFile is a FileCollection, where the files are stored
20  in a .zip file.  */
21 class ZipFile : public FileCollection {
22 public:
23   /** \anchor zipfile_openembeddedzipfile
24       Opens a Zip archive embedded in another file, by writing the zip
25       archive to the end of the file followed by the start offset of
26       the zip file. The offset must be written in zip-file byte-order
27       (little endian). The program appendzip, which is part of the
28       Zipios++ distribution can be used to append a Zip archive to a
29       file, e.g. a binary program. 
30       @throw FColException Thrown if the specified file name is not a valid zip 
31       archive.
32       @throw IOException Thrown if an I/O problem is encountered, while the directory
33       of the specified zip archive is being read. */
34   static ZipFile openEmbeddedZipFile( const string &name ) ;
35
36   /** Default constructor.
37    */
38   ZipFile() {}
39
40   /* Default Copy constructor and copy assignment operator are sufficient. */
41
42   /** Constructor. Opens the zip file name. If the zip "file" is
43       embedded in a file that contains other data, e.g. a binary
44       program, the offset of the zip file start and end must be
45       specified. 
46       @param name The filename of the zip file to open.
47       @param s_off Offset relative to the start of the file, that 
48       indicates the beginning of the zip file.
49       @param e_off Offset relative to the end of the file, that
50       indicates the end of the zip file. The offset is a positive number,
51       even though the offset is towards the beginning of the file.
52       @throw FColException Thrown if the specified file name is not a valid zip 
53       archive.
54       @throw IOException Thrown if an I/O problem is encountered, while the directory
55       of the specified zip archive is being read. */
56   explicit ZipFile( const string &name, int s_off = 0, int e_off = 0
57                     /* , ios::open_mode mode  = ios::in | ios::binary */ ) ;
58
59   explicit ZipFile( const fs::path &name, int s_off = 0, int e_off = 0
60                     /* , ios::open_mode mode  = ios::in | ios::binary */ ) ;
61
62   virtual FileCollection *clone() const ;
63
64   /** Destructor. */
65   virtual ~ZipFile() ;
66
67   virtual void close() ;
68
69   virtual istream *getInputStream( const ConstEntryPointer &entry ) ;
70   virtual istream *getInputStream( const string &entry_name, 
71                                      MatchPath matchpath = MATCH ) ;
72 private:
73   VirtualSeeker _vs ;
74   EndOfCentralDirectory  _eocd ;
75
76   bool init( istream &_zipfile ) ;
77   bool readCentralDirectory( istream &_zipfile ) ;
78   bool readEndOfCentralDirectory( istream &_zipfile ) ;
79   bool confirmLocalHeaders( istream &_zipfile ) ;
80   void setError( string error_str ) ;
81 };
82
83
84 }
85
86 #endif
87
88 /** \file
89     Header file that defines ZipFile.
90 */
91
92 /*
93   Zipios++ - a small C++ library that provides easy access to .zip files.
94   Copyright (C) 2000  Thomas Søndergaard
95   
96   This library is free software; you can redistribute it and/or
97   modify it under the terms of the GNU Lesser General Public
98   License as published by the Free Software Foundation; either
99   version 2 of the License, or (at your option) any later version.
100   
101   This library is distributed in the hope that it will be useful,
102   but WITHOUT ANY WARRANTY; without even the implied warranty of
103   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
104   Lesser General Public License for more details.
105   
106   You should have received a copy of the GNU Lesser General Public
107   License along with this library; if not, write to the Free Software
108   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
109 */