Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QZipWriter Class Reference

the QZipWriter class provides a way to create a new zip archive. More...

#include <qzipwriter_p.h>

+ Collaboration diagram for QZipWriter:

Public Types

enum  Status {
  NoError , FileWriteError , FileOpenError , FilePermissionsError ,
  FileError
}
 The following status values are possible: More...
 
enum  CompressionPolicy { AlwaysCompress , NeverCompress , AutoCompress }
 \value AlwaysCompress A file that is added is compressed. More...
 

Public Member Functions

 QZipWriter (const QString &fileName, QIODevice::OpenMode mode=(QIODevice::WriteOnly|QIODevice::Truncate))
 Create a new zip archive that operates on the archive filename.
 
 QZipWriter (QIODevice *device)
 Create a new zip archive that operates on the archive found in device.
 
 ~QZipWriter ()
 
QIODevicedevice () const
 Returns device used for writing zip archive.
 
bool isWritable () const
 Returns true if the user can write to the archive; otherwise returns false.
 
bool exists () const
 Returns true if the file exists; otherwise returns false.
 
Status status () const
 Returns a status code indicating the first error that was met by QZipWriter, or QZipWriter::NoError if no error occurred.
 
void setCompressionPolicy (CompressionPolicy policy)
 Sets the policy for compressing newly added files to the new policy.
 
CompressionPolicy compressionPolicy () const
 Returns the currently set compression policy.
 
void setCreationPermissions (QFile::Permissions permissions)
 Sets the permissions that will be used for newly added files.
 
QFile::Permissions creationPermissions () const
 Returns the currently set creation permissions.
 
void addFile (const QString &fileName, const QByteArray &data)
 Add a file to the archive with data as the file contents.
 
void addFile (const QString &fileName, QIODevice *device)
 Add a file to the archive with device as the source of the contents.
 
void addDirectory (const QString &dirName)
 Create a new directory in the archive with the specified dirName and the permissions;.
 
void addSymLink (const QString &fileName, const QString &destination)
 Create a new symbolic link in the archive with the specified dirName and the permissions; A symbolic link contains the destination (relative) path and name.
 
void close ()
 Closes the zip file.
 

Detailed Description

the QZipWriter class provides a way to create a new zip archive.

Since
4.5

QZipWriter can be used to create a zip archive containing any number of files and directories. The files in the archive will be compressed in a way that is compatible with common zip reader applications.

Definition at line 26 of file qzipwriter_p.h.

Member Enumeration Documentation

◆ CompressionPolicy

\value AlwaysCompress A file that is added is compressed.

\value NeverCompress A file that is added will be stored without changes. \value AutoCompress A file that is added will be compressed only if that will give a smaller file.

Enumerator
AlwaysCompress 
NeverCompress 
AutoCompress 

Definition at line 49 of file qzipwriter_p.h.

◆ Status

The following status values are possible:

\value NoError No error occurred. \value FileWriteError An error occurred when writing to the device. \value FileOpenError The file could not be opened. \value FilePermissionsError The file could not be accessed. \value FileError Another file error occurred.

Enumerator
NoError 
FileWriteError 
FileOpenError 
FilePermissionsError 
FileError 

Definition at line 39 of file qzipwriter_p.h.

Constructor & Destructor Documentation

◆ QZipWriter() [1/2]

QZipWriter::QZipWriter ( const QString & fileName,
QIODevice::OpenMode mode = (QIODevice::WriteOnly | QIODevice::Truncate) )
explicit

Create a new zip archive that operates on the archive filename.

The file will be opened with the mode.

See also
isValid()

Definition at line 1103 of file qzip.cpp.

References FileError, fileName, FileOpenError, FilePermissionsError, FileWriteError, QFileDevice::NoError, NoError, QFileDevice::OpenError, QFileDevice::PermissionsError, Q_UNUSED, QZipWriterPrivate::status, status(), and QFileDevice::WriteError.

+ Here is the call graph for this function:

◆ QZipWriter() [2/2]

QZipWriter::QZipWriter ( QIODevice * device)
explicit

Create a new zip archive that operates on the archive found in device.

You have to open the device previous to calling the constructor and only a device that is readable will be scanned for zip filecontent.

Definition at line 1130 of file qzip.cpp.

References device(), and Q_ASSERT.

+ Here is the call graph for this function:

◆ ~QZipWriter()

QZipWriter::~QZipWriter ( )

Definition at line 1136 of file qzip.cpp.

References close().

+ Here is the call graph for this function:

Member Function Documentation

◆ addDirectory()

void QZipWriter::addDirectory ( const QString & dirName)

Create a new directory in the archive with the specified dirName and the permissions;.

Definition at line 1290 of file qzip.cpp.

References QZipWriterPrivate::addEntry(), QZipWriterPrivate::Directory, QDir::fromNativeSeparators(), and QByteArray().

+ Here is the call graph for this function:

◆ addFile() [1/2]

void QZipWriter::addFile ( const QString & fileName,
const QByteArray & data )

Add a file to the archive with data as the file contents.

The file will be stored in the archive using the fileName which includes the full path in the archive.

The new file will get the file permissions based on the current creationPermissions and it will be compressed using the zip compression based on the current compression policy.

See also
setCreationPermissions()
setCompressionPolicy()

Definition at line 1257 of file qzip.cpp.

References QZipWriterPrivate::addEntry(), QZipWriterPrivate::File, fileName, and QDir::fromNativeSeparators().

Referenced by QZipStreamStrategy::QZipStreamStrategy(), QZipStreamStrategy::~QZipStreamStrategy(), and QZipStreamStrategy::addFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addFile() [2/2]

void QZipWriter::addFile ( const QString & fileName,
QIODevice * device )

Add a file to the archive with device as the source of the contents.

The contents returned from QIODevice::readAll() will be used as the filedata. The file will be stored in the archive using the fileName which includes the full path in the archive.

Definition at line 1269 of file qzip.cpp.

References QZipWriterPrivate::addEntry(), QIODevice::close(), device(), QZipWriterPrivate::File, fileName, FileOpenError, QDir::fromNativeSeparators(), QIODevice::open(), QIODevice::openMode(), Q_ASSERT, QIODevice::readAll(), QIODeviceBase::ReadOnly, and QZipWriterPrivate::status.

+ Here is the call graph for this function:

◆ addSymLink()

void QZipWriter::addSymLink ( const QString & fileName,
const QString & destination )

Create a new symbolic link in the archive with the specified dirName and the permissions; A symbolic link contains the destination (relative) path and name.

Definition at line 1304 of file qzip.cpp.

References QZipWriterPrivate::addEntry(), destination, QFile::encodeName(), fileName, QDir::fromNativeSeparators(), and QZipWriterPrivate::Symlink.

+ Here is the call graph for this function:

◆ close()

void QZipWriter::close ( )

Closes the zip file.

Definition at line 1312 of file qzip.cpp.

References QList< T >::at(), QIODevice::close(), QZipPrivate::comment, QZipPrivate::device, QZipPrivate::fileHeaders, header(), i, QIODevice::openMode(), QIODevice::pos(), QIODevice::seek(), QByteArray::size(), QList< T >::size(), QZipPrivate::start_of_directory, QIODevice::write(), QIODeviceBase::WriteOnly, writeUInt(), and writeUShort().

Referenced by QZipStreamStrategy::~QZipStreamStrategy(), and ~QZipWriter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compressionPolicy()

QZipWriter::CompressionPolicy QZipWriter::compressionPolicy ( ) const

Returns the currently set compression policy.

See also
setCompressionPolicy()
addFile()

Definition at line 1216 of file qzip.cpp.

References QZipWriterPrivate::compressionPolicy.

◆ creationPermissions()

QFile::Permissions QZipWriter::creationPermissions ( ) const

Returns the currently set creation permissions.

See also
setCreationPermissions()
addFile()

Definition at line 1240 of file qzip.cpp.

References QZipWriterPrivate::permissions.

◆ device()

QIODevice * QZipWriter::device ( ) const

Returns device used for writing zip archive.

Definition at line 1145 of file qzip.cpp.

References QZipPrivate::device.

Referenced by QZipWriter(), and addFile().

+ Here is the caller graph for this function:

◆ exists()

bool QZipWriter::exists ( ) const

Returns true if the file exists; otherwise returns false.

Definition at line 1161 of file qzip.cpp.

References QZipPrivate::device.

◆ isWritable()

bool QZipWriter::isWritable ( ) const

Returns true if the user can write to the archive; otherwise returns false.

Definition at line 1153 of file qzip.cpp.

References QZipPrivate::device, and QIODevice::isWritable().

+ Here is the call graph for this function:

◆ setCompressionPolicy()

void QZipWriter::setCompressionPolicy ( CompressionPolicy policy)

Sets the policy for compressing newly added files to the new policy.

Note
the default policy is AlwaysCompress
See also
compressionPolicy()
addFile()

Definition at line 1206 of file qzip.cpp.

References QZipWriterPrivate::compressionPolicy, and policy.

Referenced by QZipStreamStrategy::QZipStreamStrategy().

+ Here is the caller graph for this function:

◆ setCreationPermissions()

void QZipWriter::setCreationPermissions ( QFile::Permissions permissions)

Sets the permissions that will be used for newly added files.

Note
the default permissions are QFile::ReadOwner | QFile::WriteOwner.
See also
creationPermissions()
addFile()

Definition at line 1229 of file qzip.cpp.

References QZipWriterPrivate::permissions.

◆ status()

QZipWriter::Status QZipWriter::status ( ) const

Returns a status code indicating the first error that was met by QZipWriter, or QZipWriter::NoError if no error occurred.

Definition at line 1185 of file qzip.cpp.

References QZipWriterPrivate::status.

Referenced by QZipWriter().

+ Here is the caller graph for this function:

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