]> git.donarmstrong.com Git - flightcrew.git/blob - src/zipios/zipios++/zipoutputstreambuf.h
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / zipios / zipios++ / zipoutputstreambuf.h
1 #ifndef ZIPOUTPUTSTREAMBUF_H
2 #define ZIPOUTPUTSTREAMBUF_H
3
4 #include "zipios++/zipios-config.h"
5
6 #include <vector>
7
8 #include <zlib.h>
9
10 #include "zipios++/fcoll.h"
11 #include "zipios++/deflateoutputstreambuf.h"
12 #include "zipios++/ziphead.h"
13
14 namespace zipios {
15
16 /** ZipOutputStreambuf is a zip output streambuf filter.  */
17 class ZipOutputStreambuf : public DeflateOutputStreambuf {
18 public:
19
20   enum CompressionLevels { NO_COMPRESSION      = Z_NO_COMPRESSION, 
21                            BEST_SPEED          = Z_BEST_SPEED,
22                            BEST_COMPRESSION    = Z_BEST_COMPRESSION,
23                            DEFAULT_COMPRESSION = Z_DEFAULT_COMPRESSION  } ;
24
25   /** ZipOutputStreambuf constructor. A newly constructed ZipOutputStreambuf
26       is not ready to accept data, putNextEntry() must be invoked first.
27       @param outbuf the streambuf to use for input.
28       @param del_outbuf if true is specified outbuf will be deleted, when 
29       the ZipOutputStreambuf is destructed.  */
30   explicit ZipOutputStreambuf( streambuf *outbuf, bool del_outbuf = false ) ;
31
32   /** Closes the current entry, and positions the stream read pointer at 
33       the beginning of the next entry (if there is one). */
34   void closeEntry() ;
35
36   /** Calls finish. */
37   void close() ;
38
39   /** Closes the current entry (if one is open), then writes the Zip
40       Central Directory Structure closing the ZipOutputStream. The
41       output stream that the zip archive is being written to is not
42       closed. */
43   void finish() ;
44
45   /** Begins writing the next entry.
46       Opens the next entry in the zip archive and returns a const pointer to a 
47       FileEntry object for the entry.
48       @return a const FileEntry * containing information about the (now) current 
49       entry. */
50   void putNextEntry( const ZipCDirEntry &entry ) ;
51
52   /** Sets the global comment for the Zip archive. */
53   void setComment( const string &comment ) ;
54
55   /** Sets the compression level to be used for subsequent entries. */
56   void setLevel( int level ) ;
57
58   /** Sets the compression method to be used. only STORED and DEFLATED are
59       supported. */
60   void setMethod( StorageMethod method ) ;
61
62   /** Destructor. */
63   virtual ~ZipOutputStreambuf() ;
64
65 protected:
66   virtual int overflow( int c = EOF ) ;
67   virtual int sync() ;
68
69   void setEntryClosedState() ;
70   void updateEntryHeaderInfo() ;
71
72   // Should/could be moved to zipheadio.h ?!
73   static void writeCentralDirectory( const vector< ZipCDirEntry > &entries, 
74                                      EndOfCentralDirectory eocd,
75                                      ostream &os ) ;
76
77
78
79 private:
80   string _zip_comment ;
81   vector< ZipCDirEntry > _entries ;
82   bool _open_entry ;
83   bool _open ;
84   StorageMethod _method ;
85   int _level ;
86 };
87
88
89 } // namespace
90
91
92
93 #endif
94
95 /** \file
96     Header file that defines ZipOutputStreambuf.
97 */
98
99 /*
100   Zipios++ - a small C++ library that provides easy access to .zip files.
101   Copyright (C) 2000  Thomas Søndergaard
102   
103   This library is free software; you can redistribute it and/or
104   modify it under the terms of the GNU Lesser General Public
105   License as published by the Free Software Foundation; either
106   version 2 of the License, or (at your option) any later version.
107   
108   This library is distributed in the hope that it will be useful,
109   but WITHOUT ANY WARRANTY; without even the implied warranty of
110   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
111   Lesser General Public License for more details.
112   
113   You should have received a copy of the GNU Lesser General Public
114   License along with this library; if not, write to the Free Software
115   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
116 */