zipios 2.2.0
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-2019 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
30#include "gzipoutputstream.hpp"
31
32#include <fstream>
33
34
35namespace 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
82GZIPOutputStream::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
109void GZIPOutputStream::setFilename(std::string const& filename)
110{
111 m_ozf->setFilename(filename);
112}
113
114
123void 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
int CompressionLevel
The compression level to be used to save an entry.
Definition: fileentry.hpp:85
std::unique_ptr< std::ofstream > m_ofs
void setFilename(std::string const &filename)
Set the filename of a stream.
std::unique_ptr< GZIPOutputStreambuf > m_ozf
void setComment(std::string const &comment)
Set a comment in the stream.
void close()
Close the streams.
virtual ~GZIPOutputStream()
Destroy the output stream.
GZIPOutputStream(std::ostream &os, FileEntry::CompressionLevel compression_level)
Create a ZIP output stream object.
void finish()
Finishes the stream.
Save the output stream buffer.
This file defines zipios::GZIPOutputStream.
The zipios namespace includes the Zipios library definitions.
Definition: backbuffer.cpp:36