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::ZipOutputStream Class Reference

A ZipOutputStream to allow for data to be compressed with zlib. More...

#include <zipoutputstream.hpp>

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

Public Member Functions

 ZipOutputStream (std::ostream &os)
 Initialize a ZipOutputStream object.
 
virtual ~ZipOutputStream ()
 Clean up a ZipOutputStream object.
 
void close ()
 Close the current stream.
 
void closeEntry ()
 
void finish ()
 Finish up the output by flushing anything left.
 
void putNextEntry (FileEntry::pointer_t entry)
 Add an entry to the output stream.
 
void setComment (std::string const &comment)
 Set the global comment.
 

Private Attributes

std::unique_ptr< ZipOutputStreambufm_ozf = std::unique_ptr<ZipOutputStreambuf>()
 

Detailed Description

ZipOutputStream is an internal ostream implementation used to save a collection of files to a Zip archive file.

Definition at line 41 of file zipoutputstream.hpp.

Constructor & Destructor Documentation

◆ ZipOutputStream()

zipios::ZipOutputStream::ZipOutputStream ( std::ostream &  os)

The ZipOutputStream constructor create an output stream that will be used to save Zip data to a file.

Parameters
[in]osThe output stream to use to write the Zip archive.

Definition at line 54 of file zipoutputstream.cpp.

References m_ozf.

◆ ~ZipOutputStream()

zipios::ZipOutputStream::~ZipOutputStream ( )
virtual

The destructor makes sure that all resources allocated by the ZipOutputStream object.

Definition at line 66 of file zipoutputstream.cpp.

Member Function Documentation

◆ close()

void zipios::ZipOutputStream::close ( )

This function calls close() on the internal stream. After this call any attempt in writing to the file will fail.

The result is to ensure that the Zip archive file is complete and all buffers flushed to file.

Definition at line 89 of file zipoutputstream.cpp.

References m_ozf.

Referenced by zipios::ZipFile::saveCollectionToArchive().

◆ closeEntry()

void zipios::ZipOutputStream::closeEntry ( )

Closes the current entry updates its header with the relevant size information and positions the stream write pointer for the next entry header. Puts the stream in EOF state. Call putNextEntry() to clear the EOF stream state flag.

Definition at line 75 of file zipoutputstream.cpp.

References m_ozf.

Referenced by zipios::ZipFile::saveCollectionToArchive().

◆ finish()

void zipios::ZipOutputStream::finish ( )

This function closes the current entry (if one is open) by writing the Zip Central Directory Structure closing the ZipOutputStream. The output stream that the zip archive is being written to is not closed.

Definition at line 102 of file zipoutputstream.cpp.

References m_ozf.

Referenced by zipios::ZipFile::saveCollectionToArchive().

◆ putNextEntry()

void zipios::ZipOutputStream::putNextEntry ( FileEntry::pointer_t  entry)

This function saves the header of the entry and returns. The caller is expected to save the actual data of the file.

os.putNextEntry(entry);
FileCollection::stream_pointer_t is(collection->getInputEntry(entry->getName()));
os << is->rdbuf();
std::shared_ptr< std::istream > stream_pointer_t
A shared pointer to an input stream.
Warning
The internal class keeps a copy of the shared pointer so changing the entry from the outside may affect the results and invalidate the resulting Zip archive file. Since this class is now internal, it should not be a major problem since it is created and destroyed before the user would have a chance from doing anything to the file.
Parameters
[in]entryThe FileEntry to add to the output stream.

Definition at line 128 of file zipoutputstream.cpp.

References m_ozf.

Referenced by zipios::ZipFile::saveCollectionToArchive().

◆ setComment()

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

This function is used to setup the Global Comment of the Zip archive file.

This comment is saved at the very end of the file, attached to the EndOfCentralDirectory block.

Parameters
[in]commentThe global comment to save in the Zip archive.

Definition at line 153 of file zipoutputstream.cpp.

References m_ozf.

Referenced by zipios::ZipFile::saveCollectionToArchive().

Member Data Documentation

◆ m_ozf

std::unique_ptr<ZipOutputStreambuf> zipios::ZipOutputStream::m_ozf = std::unique_ptr<ZipOutputStreambuf>()
private

Definition at line 54 of file zipoutputstream.hpp.

Referenced by ZipOutputStream(), close(), closeEntry(), finish(), putNextEntry(), and setComment().


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