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
QZipReader Class Reference

\variable QZipReader::FileInfo::filePath The full filepath inside the archive. More...

#include <qzipreader_p.h>

+ Collaboration diagram for QZipReader:

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.
 
QIODevicedevice () 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< FileInfofileInfoList () 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.
 

Detailed Description

\variable QZipReader::FileInfo::filePath The full filepath inside the archive.

\variable QZipReader::FileInfo::isDir A boolean type indicating if the entry is a directory.

\variable QZipReader::FileInfo::isFile A boolean type, if it is one this entry is a file.

\variable QZipReader::FileInfo::isSymLink A boolean type, if it is one this entry is symbolic link.

\variable QZipReader::FileInfo::permissions A list of flags for the permissions of this entry.

\variable QZipReader::FileInfo::crc The calculated checksum as a crc type.

\variable QZipReader::FileInfo::size The total size of the unpacked content.

Since
4.5

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.

Member Enumeration Documentation

◆ 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.

Constructor & Destructor Documentation

◆ QZipReader() [1/2]

QZipReader::QZipReader ( const QString & archive,
QIODevice::OpenMode mode = QIODevice::ReadOnly )
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().

+ Here is the call graph for this function:

◆ QZipReader() [2/2]

QZipReader::QZipReader ( 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 815 of file qzip.cpp.

References device(), and Q_ASSERT.

+ Here is the call graph for this function:

◆ ~QZipReader()

QZipReader::~QZipReader ( )

Destructor.

Definition at line 824 of file qzip.cpp.

References close().

+ Here is the call graph for this function:

Member Function Documentation

◆ close()

void QZipReader::close ( )

Close the zip file.

Definition at line 1078 of file qzip.cpp.

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

Referenced by ~QZipReader().

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

◆ count()

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

+ Here is the call graph for this function:

◆ device()

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

+ Here is the caller graph for this function:

◆ entryInfoAt()

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.

See also
fileInfoList()

Definition at line 888 of file qzip.cpp.

References QZipPrivate::fillFileInfo(), and QZipReaderPrivate::scanFiles().

+ Here is the call graph for this function:

◆ exists()

bool QZipReader::exists ( ) const

Returns true if the file exists; otherwise returns false.

Definition at line 849 of file qzip.cpp.

References QZipPrivate::device.

◆ extractAll()

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 QFile::decodeName(), destination, QFile::exists(), fileData(), fileInfoList(), QFile::link(), QDir::root(), QDir::separator(), QFile::setPermissions(), and QIODeviceBase::WriteOnly.

+ Here is the call graph for this function:

◆ fileData()

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, CompressionMethodDeflated, CompressionMethodStored, QByteArray::constData(), QZipPrivate::device, Encrypted, FileHeader::file_name, QZipPrivate::fileHeaders, fileName, QString::fromLocal8Bit(), header(), i, inflate(), QIODevice::pos(), QByteArray(), qMax(), qWarning, QIODevice::read(), readUInt(), readUShort(), QZipReaderPrivate::scanFiles(), QIODevice::seek(), QList< T >::size(), QByteArray::truncate(), and ZIP_VERSION.

Referenced by extractAll().

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

◆ fileInfoList()

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

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

◆ isReadable()

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

+ Here is the call graph for this function:

◆ status()

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

+ Here is the caller graph for this function:

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