QZipReader Class

the QZipReader class provides a way to inspect the contents of a zip archive and extract individual files from it. More...

Header: #include <QZipReader>

Public Types

struct FileInfo
enum Status { NoError, FileReadError, FileOpenError, FilePermissionsError, FileError }

Public Functions

QZipReader(const QString &archive, QIODevice::OpenMode mode = QIODevice::ReadOnly)
QZipReader(QIODevice *device)
~QZipReader()
void close()
int count() const
QIODevice *device() const
FileInfo entryInfoAt(int index) const
bool exists() const
bool extractAll(const QString &destinationDir) const
QByteArray fileData(const QString &fileName) const
QList<FileInfo> fileInfoList() const
bool isReadable() const
Status status() const

Detailed Description

\internal\since 4.5

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()

Member Type Documentation

enum QZipReader::Status

The following status values are possible:

ConstantValueDescription
QZipReader::NoError0No error occurred.
QZipReader::FileReadError1An error occurred when reading from the file.
QZipReader::FileOpenError2The file could not be opened.
QZipReader::FilePermissionsError3The file could not be accessed.
QZipReader::FileError4Another file error occurred.

Member Function Documentation

[explicit] QZipReader::QZipReader(const QString &archive, QIODevice::OpenMode mode = QIODevice::ReadOnly)

Create a new zip archive that operates on the fileName. The file will be opened with the mode.

[explicit] QZipReader::QZipReader(QIODevice *device)

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.

[noexcept] QZipReader::~QZipReader()

Destructor

void QZipReader::close()

Close the zip file.

int QZipReader::count() const

Return the number of items in the zip archive.

QIODevice *QZipReader::device() const

Returns device used for reading zip archive.

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.

See also fileInfoList().

bool QZipReader::exists() const

Returns true if the file exists; otherwise returns false.

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.

QByteArray QZipReader::fileData(const QString &fileName) const

Fetch the file contents from the zip archive and return the uncompressed bytes.

QList<FileInfo> QZipReader::fileInfoList() const

Returns the list of files the archive contains.

bool QZipReader::isReadable() const

Returns true if the user can read the file; otherwise returns false.

Status QZipReader::status() const

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