![]() |
Qt 6.x
The Qt SDK
|
the QZipWriter class provides a way to create a new zip archive. More...
#include <qzipwriter_p.h>
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 () | |
QIODevice * | device () 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. | |
the QZipWriter class provides a way to create a new zip archive.
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.
\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.
enum QZipWriter::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.
|
explicit |
Create a new zip archive that operates on the archive filename.
The file will be opened with the mode.
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.
|
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.
QZipWriter::~QZipWriter | ( | ) |
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, and QDir::fromNativeSeparators().
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.
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().
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.
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.
void QZipWriter::close | ( | ) |
Closes the zip file.
Definition at line 1312 of file qzip.cpp.
References QList< T >::at(), QIODevice::close(), QZipPrivate::comment, EndOfDirectory::comment_length, QZipPrivate::device, EndOfDirectory::dir_start_offset, EndOfDirectory::directory_size, QZipPrivate::fileHeaders, header(), i, EndOfDirectory::num_dir_entries, EndOfDirectory::num_dir_entries_this_disk, QIODevice::openMode(), QIODevice::pos(), QIODevice::seek(), EndOfDirectory::signature, QByteArray::size(), QList< T >::size(), QZipPrivate::start_of_directory, QIODevice::write(), QIODeviceBase::WriteOnly, writeUInt(), and writeUShort().
Referenced by QZipStreamStrategy::~QZipStreamStrategy(), and ~QZipWriter().
QZipWriter::CompressionPolicy QZipWriter::compressionPolicy | ( | ) | const |
Returns the currently set compression policy.
Definition at line 1216 of file qzip.cpp.
References QZipWriterPrivate::compressionPolicy.
QFile::Permissions QZipWriter::creationPermissions | ( | ) | const |
Returns the currently set creation permissions.
Definition at line 1240 of file qzip.cpp.
References QZipWriterPrivate::permissions.
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().
bool QZipWriter::exists | ( | ) | const |
Returns true
if the file exists; otherwise returns false
.
Definition at line 1161 of file qzip.cpp.
References QZipPrivate::device.
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().
void QZipWriter::setCompressionPolicy | ( | CompressionPolicy | policy | ) |
Sets the policy for compressing newly added files to the new policy.
Definition at line 1206 of file qzip.cpp.
References QZipWriterPrivate::compressionPolicy, and policy.
Referenced by QZipStreamStrategy::QZipStreamStrategy().
void QZipWriter::setCreationPermissions | ( | QFile::Permissions | permissions | ) |
Sets the permissions that will be used for newly added files.
Definition at line 1229 of file qzip.cpp.
References QZipWriterPrivate::permissions.
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().