![]() |
Qt 6.x
The Qt SDK
|
\variable FileInfo::filePath The full filepath inside the archive. More...
#include <qzipreader_p.h>
Classes | |
class | FileInfo |
Public Types | |
enum | Status { NoError , FileReadError , FileOpenError , FilePermissionsError , FileError } |
The following status values are possible: More... | |
Public Member Functions | |
QZipReader (const QString &fileName, QIODevice::OpenMode mode=QIODevice::ReadOnly) | |
Create a new zip archive that operates on the fileName. | |
QZipReader (QIODevice *device) | |
Create a new zip archive that operates on the archive found in device. | |
~QZipReader () | |
Destructor. | |
QIODevice * | device () const |
Returns device used for reading zip archive. | |
bool | isReadable () const |
Returns true if the user can read the file; otherwise returns false . | |
bool | exists () const |
Returns true if the file exists; otherwise returns false . | |
QList< FileInfo > | fileInfoList () const |
Returns the list of files the archive contains. | |
int | count () const |
Return the number of items in the zip archive. | |
FileInfo | entryInfoAt (int index) const |
Returns a FileInfo of an entry in the zipfile. | |
QByteArray | fileData (const QString &fileName) const |
Fetch the file contents from the zip archive and return the uncompressed bytes. | |
bool | extractAll (const QString &destinationDir) const |
Extracts the full contents of the zip file into destinationDir on the local filesystem. | |
Status | status () const |
Returns a status code indicating the first error that was met by QZipReader, or QZipReader::NoError if no error occurred. | |
void | close () |
Close the zip file. | |
\variable FileInfo::filePath The full filepath inside the archive.
\variable FileInfo::isDir A boolean type indicating if the entry is a directory.
\variable FileInfo::isFile A boolean type, if it is one this entry is a file.
\variable FileInfo::isSymLink A boolean type, if it is one this entry is symbolic link.
\variable FileInfo::permissions A list of flags for the permissions of this entry.
\variable FileInfo::crc The calculated checksum as a crc type.
\variable FileInfo::size The total size of the unpacked content.
the QZipReader class provides a way to inspect the contents of a zip archive and extract individual files from it.
QZipReader can be used to read a zip archive either from a file or from any device. An in-memory QBuffer for instance. The reader can be used to read which files are in the archive using fileInfoList() and entryInfoAt() but also to extract individual files using fileData() or even to extract all files in the archive using extractAll()
Definition at line 28 of file qzipreader_p.h.
enum QZipReader::Status |
The following status values are possible:
\value NoError No error occurred. \value FileReadError An error occurred when reading from the file. \value FileOpenError The file could not be opened. \value FilePermissionsError The file could not be accessed. \value FileError Another file error occurred.
Enumerator | |
---|---|
NoError | |
FileReadError | |
FileOpenError | |
FilePermissionsError | |
FileError |
Definition at line 66 of file qzipreader_p.h.
|
explicit |
Create a new zip archive that operates on the fileName.
The file will be opened with the mode.
Definition at line 786 of file qzip.cpp.
References error, FileError, FileOpenError, FilePermissionsError, FileReadError, QFileDevice::NoError, NoError, QFileDevice::OpenError, QFileDevice::PermissionsError, Q_UNUSED, QFileDevice::ReadError, QZipReaderPrivate::status, and status().
|
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 815 of file qzip.cpp.
References device(), and Q_ASSERT.
QZipReader::~QZipReader | ( | ) |
void QZipReader::close | ( | ) |
Close the zip file.
Definition at line 1078 of file qzip.cpp.
References QIODevice::close(), and QZipPrivate::device.
Referenced by ~QZipReader().
int QZipReader::count | ( | ) | const |
Return the number of items in the zip archive.
Definition at line 875 of file qzip.cpp.
References QZipPrivate::fileHeaders, QZipReaderPrivate::scanFiles(), and QList< T >::size().
QIODevice * QZipReader::device | ( | ) | const |
Returns device used for reading zip archive.
Definition at line 833 of file qzip.cpp.
References QZipPrivate::device.
Referenced by QZipReader().
QZipReader::FileInfo QZipReader::entryInfoAt | ( | int | index | ) | const |
Returns a FileInfo of an entry in the zipfile.
The index is the index into the directory listing of the zipfile. Returns an invalid FileInfo if index is out of boundaries.
Definition at line 888 of file qzip.cpp.
References QZipPrivate::fillFileInfo(), and QZipReaderPrivate::scanFiles().
bool QZipReader::exists | ( | ) | const |
Returns true
if the file exists; otherwise returns false
.
Definition at line 849 of file qzip.cpp.
References QZipPrivate::device.
bool QZipReader::extractAll | ( | const QString & | destinationDir | ) | const |
Extracts the full contents of the zip file into destinationDir on the local filesystem.
In case writing or linking a file fails, the extraction will be aborted.
Definition at line 984 of file qzip.cpp.
References QFileInfo::absolutePath(), QString::contains(), QFile::decodeName(), destination, QFile::exists(), fi, fileData(), fileInfoList(), QFileInfo::filePath(), QFileInfo::isDir(), QFileInfo::isFile(), QFileInfo::isSymLink(), QString::lastIndexOf(), QString::left(), QFile::link(), QDir::mkpath(), QFileInfo::permissions(), QDir::root(), QDir::separator(), QFile::setPermissions(), and QIODeviceBase::WriteOnly.
QByteArray QZipReader::fileData | ( | const QString & | fileName | ) | const |
Fetch the file contents from the zip archive and return the uncompressed bytes.
Definition at line 899 of file qzip.cpp.
References QList< T >::at(), compressed, LocalFileHeader::compression_method, CompressionMethodDeflated, CompressionMethodStored, QByteArray::constData(), QByteArray::data(), QZipPrivate::device, Encrypted, LocalFileHeader::extra_field_length, FileHeader::file_name, LocalFileHeader::file_name_length, QZipPrivate::fileHeaders, fileName, QString::fromLocal8Bit(), header(), i, inflate(), QIODevice::pos(), qMax(), qWarning, QIODevice::read(), readUInt(), readUShort(), QByteArray::resize(), QZipReaderPrivate::scanFiles(), QIODevice::seek(), QByteArray::size(), QList< T >::size(), QByteArray::truncate(), and ZIP_VERSION.
Referenced by extractAll().
QList< QZipReader::FileInfo > QZipReader::fileInfoList | ( | ) | const |
Returns the list of files the archive contains.
Definition at line 860 of file qzip.cpp.
References QZipPrivate::fileHeaders, files, QZipPrivate::fillFileInfo(), i, QZipReaderPrivate::scanFiles(), and QList< T >::size().
Referenced by extractAll().
bool QZipReader::isReadable | ( | ) | const |
Returns true
if the user can read the file; otherwise returns false
.
Definition at line 841 of file qzip.cpp.
References QZipPrivate::device, and QIODevice::isReadable().
QZipReader::Status QZipReader::status | ( | ) | const |
Returns a status code indicating the first error that was met by QZipReader, or QZipReader::NoError if no error occurred.
Definition at line 1070 of file qzip.cpp.
References QZipReaderPrivate::status.
Referenced by QZipReader().