zipios++  2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
gzipoutputstream.cpp
Go to the documentation of this file.
1 /*
2  Zipios++ - a small C++ library that provides easy access to .zip files.
3 
4  Copyright (C) 2000-2007 Thomas Sondergaard
5  Copyright (C) 2015 Made to Order Software Corporation
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
30 #include "gzipoutputstream.hpp"
31 
32 #include <fstream>
33 
34 
35 namespace zipios
36 {
37 
64  //: std::ostream() -- auto-init
65  //, m_ofs(nullptr) -- auto-init
66  : m_ozf(new GZIPOutputStreambuf(os.rdbuf(), compression_level))
67 {
68  init(m_ozf.get());
69 }
70 
71 
82 GZIPOutputStream::GZIPOutputStream(std::string const& filename, FileEntry::CompressionLevel compression_level)
83  : std::ostream(0)
84  , m_ofs(new std::ofstream(filename.c_str(), std::ios::out | std::ios::binary))
85  , m_ozf(new GZIPOutputStreambuf(m_ofs->rdbuf(), compression_level))
86 {
87  init(m_ozf.get());
88 }
89 
90 
96 {
97 }
98 
99 
109 void GZIPOutputStream::setFilename(std::string const& filename)
110 {
111  m_ozf->setFilename(filename);
112 }
113 
114 
123 void GZIPOutputStream::setComment(std::string const& comment)
124 {
125  m_ozf->setComment(comment);
126 }
127 
128 
138 {
139  m_ozf->close();
140  if(m_ofs)
141  {
142  m_ofs->close();
143  }
144 }
145 
146 
151 {
152  m_ozf->finish();
153 }
154 
155 
156 } // zipios namespace
157 
158 // Local Variables:
159 // mode: cpp
160 // indent-tabs-mode: nil
161 // c-basic-offset: 4
162 // tab-width: 4
163 // End:
164 
165 // vim: ts=4 sw=4 et
std::unique_ptr< GZIPOutputStreambuf > m_ozf
void setFilename(std::string const &filename)
Set the filename of a stream.
virtual ~GZIPOutputStream()
Destroy the output stream.
Save the output stream buffer.
void setComment(std::string const &comment)
Set a comment in the stream.
GZIPOutputStream(std::ostream &os, FileEntry::CompressionLevel compression_level)
Create a ZIP output stream object.
This file defines zipios::GZIPOutputStream.
int CompressionLevel
The compression level to be used to save an entry.
Definition: fileentry.hpp:85
void close()
Close the streams.
void finish()
Finishes the stream.
std::unique_ptr< std::ofstream > m_ofs