Zipios++
zipoutputstream.cpp
Go to the documentation of this file.
1 
2 #include "zipios++/zipios-config.h"
3 
4 #include "zipios++/meta-iostreams.h"
5 
8 
9 using std::ostream;
10 
11 namespace zipios {
12 
14  : ostream( 0 ),
15 // SGIs basic_ifstream calls istream with 0, but calls basic_ios constructor first??
16  ofs( 0 )
17 {
18  ozf = new ZipOutputStreambuf( os.rdbuf() ) ;
19 
20  init( ozf ) ;
21 }
22 
23 
24 ZipOutputStream::ZipOutputStream( const std::string &filename )
25  : ostream( 0 ),
26  ofs( 0 )
27 {
28  ofs = new std::ofstream( filename.c_str(), std::ios::out | std::ios::binary ) ;
29  ozf = new ZipOutputStreambuf( ofs->rdbuf() ) ;
30  this->init( ozf ) ;
31 }
32 
34  ozf->closeEntry() ;
35 }
36 
37 
39  ozf->close() ;
40  if ( ofs )
41  ofs->close() ;
42 }
43 
44 
46  ozf->finish() ;
47 }
48 
49 
51  ozf->putNextEntry( entry ) ;
52 }
53 
54 void ZipOutputStream::putNextEntry(const std::string& entryName) {
55  putNextEntry( ZipCDirEntry(entryName));
56 }
57 
58 
59 void ZipOutputStream::setComment( const std::string &comment ) {
60  ozf->setComment( comment ) ;
61 }
62 
63 
64 void ZipOutputStream::setLevel( int level ) {
65  ozf->setLevel( level ) ;
66 }
67 
68 
69 void ZipOutputStream::setMethod( StorageMethod method ) {
70  ozf->setMethod( method ) ;
71 }
72 
73 
75  // It's ok to call delete with a Null pointer.
76  delete ozf ;
77  delete ofs ;
78 }
79 
80 } // namespace
81 
86 /*
87  Zipios++ - a small C++ library that provides easy access to .zip files.
88  Copyright (C) 2000 Thomas Søndergaard
89 
90  This library is free software; you can redistribute it and/or
91  modify it under the terms of the GNU Lesser General Public
92  License as published by the Free Software Foundation; either
93  version 2 of the License, or (at your option) any later version.
94 
95  This library is distributed in the hope that it will be useful,
96  but WITHOUT ANY WARRANTY; without even the implied warranty of
97  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
98  Lesser General Public License for more details.
99 
100  You should have received a copy of the GNU Lesser General Public
101  License along with this library; if not, write to the Free Software
102  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
103 */
Header file that defines ZipOutputStreambuf.
ZipOutputStream(std::ostream &os)
ZipOutputStream constructor.
void setMethod(StorageMethod method)
Sets the compression method to be used.
Header file that defines ZipOutputStream.
void setComment(const string &comment)
Sets the global comment for the Zip archive.
Specialization of ZipLocalEntry, that add fields for storing the extra information, that is only present in the entries in the zip central directory and not in the local entry headers.
Definition: ziphead.h:102
void closeEntry()
Closes the current entry, and positions the stream read pointer at the beginning of the next entry (i...
virtual ~ZipOutputStream()
Destructor.
void setMethod(StorageMethod method)
Sets the compression method to be used.
void setComment(const std::string &comment)
Sets the global comment for the Zip archive.
ZipOutputStreambuf is a zip output streambuf filter.
void setLevel(int level)
Sets the compression level to be used for subsequent entries.
void putNextEntry(const ZipCDirEntry &entry)
void putNextEntry(const ZipCDirEntry &entry)
Begins writing the next entry.
void closeEntry()
Closes the current entry updates its header with the relevant size information and positions the stre...
void finish()
Closes the current entry (if one is open), then writes the Zip Central Directory Structure closing th...
void close()
Calls finish and if the ZipOutputStream was created with a filename as a parameter that file is close...
void setLevel(int level)
Sets the compression level to be used for subsequent entries.
void finish()
Closes the current entry (if one is open), then writes the Zip Central Directory Structure closing th...