| Version: 3.3.1

Public Member Functions | List of all members
wxZipOutputStream Class Reference
Class List by Category » Archive support | Class List by Category » Streams

`#include <wx/zipstrm.h>`

Inheritance diagram for wxZipOutputStream:
[legend]

## Detailed Description

Output stream for writing zip files.

wxZipOutputStream::PutNextEntry() is used to create a new entry in the output zip, then the entry's data is written to the wxZipOutputStream. Another call to wxZipOutputStream::PutNextEntry() closes the current entry and begins the next.

##

Library: wxBase
Category: Archive support, Streams

See also
  Archive Formats, wxZipEntry, wxZipInputStream

## Public Member Functions
virtual | ~wxZipOutputStream ()
| The destructor calls Close() to finish writing the zip if it has not been called already. More...
bool | Close ()
| Finishes writing the zip, returning true if successful. More...
bool | CloseEntry ()
| Close the current entry. More...
bool | CopyArchiveMetaData (wxZipInputStream &inputStream)
| Transfers the zip comment from the wxZipInputStream to this output stream. More...
bool | CopyEntry (wxZipEntry *entry, wxZipInputStream &inputStream)
| Takes ownership of entry and uses it to create a new entry in the zip. More...
bool | PutNextDirEntry (const wxString &name, const wxDateTime &dt=wxDateTime::Now())
| Create a new directory entry (see wxArchiveEntry::IsDir) with the given name and timestamp. More...
void | SetComment (const wxString &comment)
| Sets a comment for the zip as a whole. More...
void | SetFormat (wxZipArchiveFormat format)
| Set the format of the archive. More...
wxZipArchiveFormat | GetFormat () const
| Get the format of the archive. More...
| wxZipOutputStream (wxOutputStream &stream, int level=-1, wxMBConv &conv=wxConvUTF8)
| Constructor. More...
| wxZipOutputStream (wxOutputStream *stream, int level=-1, wxMBConv &conv=wxConvUTF8)
| Constructor. More...
int | GetLevel () const
| Set the compression level that will be used the next time an entry is created. More...
void | SetLevel (int level)
| Set the compression level that will be used the next time an entry is created. More...
bool | PutNextEntry (wxZipEntry *entry)
| Takes ownership of entry and uses it to create a new entry in the zip. More...
bool | PutNextEntry (const wxString &name, const wxDateTime &dt=wxDateTime::Now(), wxFileOffset size=wxInvalidOffset)
| Create a new entry with the given name, timestamp and size. More...
Public Member Functions inherited from wxArchiveOutputStream
virtual | ~wxArchiveOutputStream ()
| Calls Close() if it has not already been called. More...
virtual bool | CopyArchiveMetaData (wxArchiveInputStream &stream)=0
| Some archive formats have additional meta-data that applies to the archive as a whole. More...
virtual bool | CopyEntry (wxArchiveEntry *entry, wxArchiveInputStream &stream)=0
| Takes ownership of entry and uses it to create a new entry in the archive. More...
virtual bool | PutNextEntry (wxArchiveEntry *entry)=0
| Takes ownership of entry and uses it to create a new entry in the archive. More...
Public Member Functions inherited from wxFilterOutputStream
| wxFilterOutputStream (wxOutputStream &stream)
| Initializes a "filter" stream. More...
| wxFilterOutputStream (wxOutputStream *stream)
| Initializes a "filter" stream. More...
Public Member Functions inherited from wxOutputStream
| wxOutputStream ()
| Creates a dummy wxOutputStream object. More...
virtual | ~wxOutputStream ()
| Destructor. More...
virtual size_t | LastWrite () const
| Returns the number of bytes written during the last Write(). More...
void | PutC (char c)
| Puts the specified character in the output queue and increments the stream position. More...
virtual wxFileOffset | SeekO (wxFileOffset pos, wxSeekMode mode=wxFromStart)
| Changes the stream current position. More...
virtual wxFileOffset | TellO () const
| Returns the current stream position. More...
virtual wxOutputStream & | Write (const void *buffer, size_t size)
| Writes up to the specified amount of bytes using the data of buffer. More...
wxOutputStream & | Write (wxInputStream &stream_in)
| Reads data from the specified input stream and stores them in the current stream. More...
bool | WriteAll (const void *buffer, size_t size)
| Writes exactly the specified number of bytes from the buffer. More...
Public Member Functions inherited from wxStreamBase
| wxStreamBase ()
| Creates a dummy stream object. More...
virtual | ~wxStreamBase ()
| Destructor. More...
wxStreamError | GetLastError () const
| This function returns the last error. More...
virtual wxFileOffset | GetLength () const
| Returns the length of the stream in bytes. More...
virtual size_t | GetSize () const
| This function returns the size of the stream. More...
virtual bool | IsOk () const
| Returns true if no error occurred on the stream. More...
virtual bool | IsSeekable () const
| Returns true if the stream supports seeking to arbitrary offsets. More...
void | Reset (wxStreamError error=wxSTREAM_NO_ERROR)
| Resets the stream state. More...
bool | operator! () const
| Returns the opposite of IsOk(). More...

## Additional Inherited Members
Protected Member Functions inherited from wxOutputStream
size_t | OnSysWrite (const void *buffer, size_t bufsize)
| Internal function. More...
Protected Member Functions inherited from wxStreamBase
virtual wxFileOffset | OnSysSeek (wxFileOffset pos, wxSeekMode mode)
| Internal function. More...
virtual wxFileOffset | OnSysTell () const
| Internal function. More...

## Constructor & Destructor Documentation

## ◆ wxZipOutputStream() [1/2]

wxZipOutputStream::wxZipOutputStream | ( | wxOutputStream & | stream,
|  | int | level = `-1`,
|  | wxMBConv & | conv = `wxConvUTF8`
| ) |  |

Constructor.

level is the compression level to use. It can be a value between 0 and 9 or -1 to use the default value which currently is equivalent to 6.

If the parent stream is passed as a pointer then the new filter stream takes ownership of it. If it is passed by reference then it does not. In a Unicode build the third parameter conv is used to translate the filename and comment fields to an 8-bit encoding. It has no effect on the stream's data.

Since version 3.1.1, filenames in the generated archive will be encoded using UTF-8 and marked according to ZIP specification. To get the previous behaviour wxConvLocal may be provided as the conv object. Please note that not all unzip applications are fully ZIP spec compatible and may not correctly decode UTF-8 characters. For the best interoperability using only ASCII characters is the safest option.

## ◆ wxZipOutputStream() [2/2]

wxZipOutputStream::wxZipOutputStream | ( | wxOutputStream * | stream,
|  | int | level = `-1`,
|  | wxMBConv & | conv = `wxConvUTF8`
| ) |  |

Constructor.

level is the compression level to use. It can be a value between 0 and 9 or -1 to use the default value which currently is equivalent to 6.

If the parent stream is passed as a pointer then the new filter stream takes ownership of it. If it is passed by reference then it does not. In a Unicode build the third parameter conv is used to translate the filename and comment fields to an 8-bit encoding. It has no effect on the stream's data.

Since version 3.1.1, filenames in the generated archive will be encoded using UTF-8 and marked according to ZIP specification. To get the previous behaviour wxConvLocal may be provided as the conv object. Please note that not all unzip applications are fully ZIP spec compatible and may not correctly decode UTF-8 characters. For the best interoperability using only ASCII characters is the safest option.

## ◆ ~wxZipOutputStream()

virtual wxZipOutputStream::~wxZipOutputStream | ( |  | ) |
| virtual

The destructor calls Close() to finish writing the zip if it has not been called already.

## Member Function Documentation

## ◆ Close()

bool wxZipOutputStream::Close | ( |  | ) |
| virtual

Finishes writing the zip, returning true if successful.

Called by the destructor if not called explicitly.

Reimplemented from wxArchiveOutputStream.

## ◆ CloseEntry()

bool wxZipOutputStream::CloseEntry | ( |  | ) |
| virtual

Close the current entry.

It is called implicitly whenever another new entry is created with CopyEntry() or PutNextEntry(), or when the zip is closed.

Implements wxArchiveOutputStream.

## ◆ CopyArchiveMetaData()

bool wxZipOutputStream::CopyArchiveMetaData | ( | wxZipInputStream & | inputStream | ) |

Transfers the zip comment from the wxZipInputStream to this output stream.

## ◆ CopyEntry()

bool wxZipOutputStream::CopyEntry | ( | wxZipEntry * | entry,
|  | wxZipInputStream & | inputStream
| ) |  |

Takes ownership of entry and uses it to create a new entry in the zip.

entry is then opened in inputStream and its contents copied to this stream.

CopyEntry() is much more efficient than transferring the data using Read() and Write() since it will copy them without decompressing and recompressing them.

For zips on seekable streams, entry must be from the same zip file as inputStream. For non-seekable streams, entry must also be the last thing read from inputStream.

## ◆ GetFormat()

wxZipArchiveFormat wxZipOutputStream::GetFormat | ( |  | ) | const

Get the format of the archive.

This returns the value passed to SetFormat() and not necessarily the actual archive format (e.g. this method could return wxZIP_FORMAT_DEFAULT even if a ZIP64 will end up being created).

Since
  3.1.1

## ◆ GetLevel()

int wxZipOutputStream::GetLevel | ( |  | ) | const

Set the compression level that will be used the next time an entry is created.

It can be a value between 0 and 9 or -1 to use the default value which currently is equivalent to 6.

## ◆ PutNextDirEntry()

bool wxZipOutputStream::PutNextDirEntry | ( | const wxString & | name,
|  | const wxDateTime & | dt = `wxDateTime::Now()`
| ) |  |
| virtual

Create a new directory entry (see wxArchiveEntry::IsDir) with the given name and timestamp.

PutNextEntry() can also be used to create directory entries, by supplying a name with a trailing path separator.

Implements wxArchiveOutputStream.

## ◆ PutNextEntry() [1/2]

bool wxZipOutputStream::PutNextEntry | ( | const wxString & | name,
|  | const wxDateTime & | dt = `wxDateTime::Now()`,
|  | wxFileOffset | size = `wxInvalidOffset`
| ) |  |
| virtual

Create a new entry with the given name, timestamp and size.

If you do not specify a size and plan to put more than 4GB data into the entry see SetFormat()

Implements wxArchiveOutputStream.

## ◆ PutNextEntry() [2/2]

bool wxZipOutputStream::PutNextEntry | ( | wxZipEntry * | entry | ) |

Takes ownership of entry and uses it to create a new entry in the zip.

If you do not specify a size and plan to put more than 4GB data into the entry see SetFormat()

## ◆ SetComment()

void wxZipOutputStream::SetComment | ( | const wxString & | comment | ) |

Sets a comment for the zip as a whole.

It is written at the end of the zip.

## ◆ SetFormat()

void wxZipOutputStream::SetFormat | ( | wxZipArchiveFormat | format | ) |

Set the format of the archive.

The normal zip format is limited to single files and the complete archive smaller than 4GB with less than 65k files. If any of these limits are exceeded, this class will automatically create a ZIP64 file, so in most situations calling SetFormat() is not necessary.

However, to support single entries with more than 4GB of data (compressed or original) whose sizes are unknown when adding the entry with PutNextEntry(), the format has to be set to wxZIP_FORMAT_ZIP64 before adding such entries.

Since
  3.1.1

## ◆ SetLevel()

void wxZipOutputStream::SetLevel | ( | int | level | ) |

Set the compression level that will be used the next time an entry is created.

It can be a value between 0 and 9 or -1 to use the default value which currently is equivalent to 6.