zipios++  2.0.2
Zipios++ – a small C++ library that provides 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 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. More...
 
virtual ~ZipOutputStream ()
 Clean up a ZipOutputStream object. More...
 
void close ()
 Close the current stream. More...
 
void closeEntry ()
 
void finish ()
 Finish up the output by flushing anything left. More...
 
void putNextEntry (FileEntry::pointer_t entry)
 Add an entry to the output stream. More...
 
void setComment (std::string const &comment)
 Set the global comment. More...
 

Private Attributes

std::unique_ptr< std::ofstream > m_ofs
 
std::unique_ptr
< ZipOutputStreambuf
m_ozf
 

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

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.

zipios::ZipOutputStream::~ZipOutputStream ( )
virtual

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

Definition at line 67 of file zipoutputstream.cpp.

Member Function Documentation

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 90 of file zipoutputstream.cpp.

References m_ozf.

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

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 76 of file zipoutputstream.cpp.

References m_ozf.

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

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 103 of file zipoutputstream.cpp.

References m_ozf.

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

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();
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 129 of file zipoutputstream.cpp.

References m_ozf.

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

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 154 of file zipoutputstream.cpp.

References m_ozf.

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

Member Data Documentation

std::unique_ptr<std::ofstream> zipios::ZipOutputStream::m_ofs
private

Definition at line 54 of file zipoutputstream.hpp.

std::unique_ptr<ZipOutputStreambuf> zipios::ZipOutputStream::m_ozf
private

Definition at line 55 of file zipoutputstream.hpp.

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


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