zipios 2.3.4
Zipios -- a small C++ library providing easy access to .zip files.
Public Member Functions | Private Attributes | List of all members
zipios::GZIPOutputStream Class Reference

A stream implementation that outputs data to a ZIP file. More...

#include <gzipoutputstream.hpp>

Inheritance diagram for zipios::GZIPOutputStream:
Inheritance graph
[legend]
Collaboration diagram for zipios::GZIPOutputStream:
Collaboration graph
[legend]

Public Member Functions

 GZIPOutputStream (std::ostream &os, FileEntry::CompressionLevel compression_level)
 Create a ZIP output stream object.
 
 GZIPOutputStream (std::string const &filename, FileEntry::CompressionLevel compression_level)
 Create a named ZIP stream for output.
 
virtual ~GZIPOutputStream ()
 Destroy the output stream.
 
void close ()
 Close the streams.
 
void finish ()
 Finishes the stream.
 
void setComment (std::string const &comment)
 Set a comment in the stream.
 
void setFilename (std::string const &filename)
 Set the filename of a stream.
 

Private Attributes

std::unique_ptr< std::ofstream > m_ofs = std::unique_ptr<std::ofstream>()
 
std::unique_ptr< GZIPOutputStreambufm_ozf = std::unique_ptr<GZIPOutputStreambuf>()
 

Detailed Description

GZIPOutputStream is an ostream that writes the output to a zip file. The interface approximates the interface of the Java GZIPOutputStream.

It can be used with either an existing std::ostream object, or a filename.

Definition at line 42 of file gzipoutputstream.hpp.

Constructor & Destructor Documentation

◆ GZIPOutputStream() [1/2]

zipios::GZIPOutputStream::GZIPOutputStream ( std::ostream &  os,
FileEntry::CompressionLevel  compression_level 
)

This constructor creates a zip stream from an existing standard output stream.

Warning
You must keep the output stream valid for as long as this object exists (although this object close() function can be used to close the os stream.)
Parameters
[in,out]osostream to which the compressed zip archive is written.
[in]compression_levelThe compression level to use to compress.

Definition at line 63 of file gzipoutputstream.cpp.

References m_ozf.

◆ GZIPOutputStream() [2/2]

zipios::GZIPOutputStream::GZIPOutputStream ( std::string const &  filename,
FileEntry::CompressionLevel  compression_level 
)
Note
The filename is not automatically saved as part of the stream. To do so, call the setFilename() function.
Parameters
[in]filenameName of the file where the zip archive is to be written.
[in]compression_levelThe compression level to use to compress.

Definition at line 80 of file gzipoutputstream.cpp.

References m_ozf.

◆ ~GZIPOutputStream()

zipios::GZIPOutputStream::~GZIPOutputStream ( )
virtual

The destructor ensures that all allocated resources get destroyed.

Definition at line 93 of file gzipoutputstream.cpp.

Member Function Documentation

◆ close()

void zipios::GZIPOutputStream::close ( )

This function closes the streams making sure that all data gets saved in the output file.

It is not required since destroying the object will also force a close.

Definition at line 135 of file gzipoutputstream.cpp.

References m_ofs, and m_ozf.

◆ finish()

void zipios::GZIPOutputStream::finish ( )

Definition at line 148 of file gzipoutputstream.cpp.

References m_ozf.

◆ setComment()

void zipios::GZIPOutputStream::setComment ( std::string const &  comment)

This function can be used to add a comment to the zip file.

A comment is optional.

Parameters
[in]commentThe comment to attach to this stream.

Definition at line 121 of file gzipoutputstream.cpp.

References m_ozf.

◆ setFilename()

void zipios::GZIPOutputStream::setFilename ( std::string const &  filename)

This function can be used to set the name of the file being added to this stream.

The filename is optional.

Parameters
[in]filenameThe filename to attach to this stream.

Definition at line 107 of file gzipoutputstream.cpp.

References m_ozf.

Member Data Documentation

◆ m_ofs

std::unique_ptr<std::ofstream> zipios::GZIPOutputStream::m_ofs = std::unique_ptr<std::ofstream>()
private

Definition at line 55 of file gzipoutputstream.hpp.

Referenced by close().

◆ m_ozf

std::unique_ptr<GZIPOutputStreambuf> zipios::GZIPOutputStream::m_ozf = std::unique_ptr<GZIPOutputStreambuf>()
private

The documentation for this class was generated from the following files: