zipios 2.3.4
Zipios -- a small C++ library providing 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-2022 Made to Order Software Corp. All Rights Reserved
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 : m_ozf(std::make_unique<GZIPOutputStreambuf>(os.rdbuf(), compression_level))
65{
66 init(m_ozf.get());
67}
68
69
80GZIPOutputStream::GZIPOutputStream(std::string const & filename, FileEntry::CompressionLevel compression_level)
81 : std::ostream(0)
82 , m_ofs(std::make_unique<std::ofstream>(filename.c_str(), std::ios::out | std::ios::binary))
83 , m_ozf(std::make_unique<GZIPOutputStreambuf>(m_ofs->rdbuf(), compression_level))
84{
85 init(m_ozf.get());
86}
87
88
96
97
107void GZIPOutputStream::setFilename(std::string const & filename)
108{
109 m_ozf->setFilename(filename);
110}
111
112
121void GZIPOutputStream::setComment(std::string const & comment)
122{
123 m_ozf->setComment(comment);
124}
125
126
136{
137 m_ozf->close();
138 if(m_ofs)
139 {
140 m_ofs->close();
141 }
142}
143
144
149{
150 m_ozf->finish();
151}
152
153
154} // zipios namespace
155
156// Local Variables:
157// mode: cpp
158// indent-tabs-mode: nil
159// c-basic-offset: 4
160// tab-width: 4
161// End:
162
163// 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.