Quark  0.1
ZipFile Class Reference

A class representing a Zip archive. More...

#include <ZipFile.h++>

Public Member Functions

 ZipFile (const QString &file)
 Constructs a new ZipFile for the given file path. More...
 
virtual ~ZipFile ()
 Destructor. More...
 
bool open (QIODevice::OpenMode openMode, const QString &password=QString())
 Opens the Zip archive. More...
 
bool close ()
 Closes the Zip archive. More...
 
bool isOpen () const
 Tests if the Zip archive is currently open. More...
 
QString archiveComment ()
 Returns the Zip archive's comment. More...
 
bool setArchiveComment (const QString &comment)
 Sets the Zip archive's comment. More...
 
qint64 numEntries ()
 Returns the number of entries in the Zip archive. More...
 
QString getEntryPath (qint64 index)
 Returns the file path for the entry at the specified index. More...
 
bool getEntry (qint64 index, ZipEntry &entry)
 Retrieves the entry at the specified index in the Zip archive. More...
 
bool getEntry (const QString &path, ZipEntry &entry, bool ignoreCase=false)
 Retrieves the entry with the specified file path in the Zip archive. More...
 
QString getEntryComment (qint64 index)
 Retrieves the comment for the entry at the specified index in the Zip archive. More...
 
bool setEntryComment (qint64 index, const QString &comment)
 Sets the comment for the entry at the specified index in the Zip archive. More...
 
bool removeEntry (qint64 index)
 Removes the entry at the specified index from the Zip archive. More...
 
bool renameEntry (qint64 index, const QString &newPath)
 Changes the file path of the entry at the specified index in the Zip archive. More...
 
bool openEntry (qint64 index)
 Opens the entry at the specified index in the Zip archive. More...
 
bool isEntryOpen () const
 Tests if an entry is currently opened. More...
 
int readEntry (char *buf, int count)
 Reads (and decompresses) data from the currently opened entry. More...
 
void closeEntry ()
 Closes the currently opened entry, if any. More...
 
bool extractEntry (const ZipEntry &entry, const QString &outputPath)
 Extracts the contents of a file entry from the Zip archive. More...
 
bool addDirectory (const QString &zipPath)
 Adds a directory entry to the Zip archive. More...
 
bool addFile (const QString &path, const QString &zipPath)
 Adds a file entry to the Zip archive. More...
 
QString error () const
 Returns the most recently generated Zip error message. More...
 

Friends

class ZipEntry
 

Detailed Description

A class representing a Zip archive.

The class can be used to both read and write Zip archives.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ ZipFile()

ZipFile ( const QString &  file)

Constructs a new ZipFile for the given file path.

◆ ~ZipFile()

virtual ~ZipFile ( )
virtual

Destructor.

Closes the file if it is open.

Member Function Documentation

◆ addDirectory()

bool addDirectory ( const QString &  zipPath)

Adds a directory entry to the Zip archive.

Parameters
zipPathThe file path for the new entry.
Returns
true if the entry was successfully added, false otherwise.

◆ addFile()

bool addFile ( const QString &  path,
const QString &  zipPath 
)

Adds a file entry to the Zip archive.

Parameters
pathThe path of the file which should be written into the Zip archive.
zipPathThe file path for the new entry.
Returns
true if the entry was successfully added, false otherwise.

◆ archiveComment()

QString archiveComment ( )

Returns the Zip archive's comment.

◆ close()

bool close ( )

Closes the Zip archive.

Note that when writing a Zip archive, the file may not actually be created and written to the filesystem until it is closed.

Returns
true if the file was successfully opened, false otherwise.

◆ closeEntry()

void closeEntry ( )

Closes the currently opened entry, if any.

◆ error()

QString error ( ) const
inline

Returns the most recently generated Zip error message.

◆ extractEntry()

bool extractEntry ( const ZipEntry entry,
const QString &  outputPath 
)

Extracts the contents of a file entry from the Zip archive.

Parameters
entryThe entry to be extracted.
outputPathThe path to which the decompressed file data should be written.
Returns
true if the entry was successfully extracted, false otherwise.

◆ getEntry() [1/2]

bool getEntry ( qint64  index,
ZipEntry entry 
)

Retrieves the entry at the specified index in the Zip archive.

Parameters
indexThe index
entryThe ZipEntry object in which to place details about the entry.
Returns
true if the entry was successfully retrieved, false otherwise.

◆ getEntry() [2/2]

bool getEntry ( const QString &  path,
ZipEntry entry,
bool  ignoreCase = false 
)

Retrieves the entry with the specified file path in the Zip archive.

Parameters
pathfilePath
entryThe ZipEntry object in which to place details about the entry.
ignoreCaseA flag indicating whether the search for a matching file path in the archive should be case-insensitive.
Returns
true if the entry was successfully retrieved, false otherwise.

◆ getEntryComment()

QString getEntryComment ( qint64  index)

Retrieves the comment for the entry at the specified index in the Zip archive.

Parameters
indexThe index.
Returns
The comment, or a null string if the entry has no comment or if no such entry exists.

◆ getEntryPath()

QString getEntryPath ( qint64  index)

Returns the file path for the entry at the specified index.

Parameters
indexThe index.
Returns
The file path, or a null string if no such entry exists.

◆ isEntryOpen()

bool isEntryOpen ( ) const

Tests if an entry is currently opened.

◆ isOpen()

bool isOpen ( ) const

Tests if the Zip archive is currently open.

◆ numEntries()

qint64 numEntries ( )

Returns the number of entries in the Zip archive.

◆ open()

bool open ( QIODevice::OpenMode  openMode,
const QString &  password = QString() 
)

Opens the Zip archive.

Parameters
openModeThe open mode. Must be either QIODevice::ReadOnly or QIODevice::WriteOnly.
passwordThe password for the archive, if any.
Returns
true if the file was successfully opened, false otherwise.

◆ openEntry()

bool openEntry ( qint64  index)

Opens the entry at the specified index in the Zip archive.

An entry must be opened before it can be read from. Only one entry can be opened at any given time.

Parameters
indexThe index.
Returns
true if the entry was successfully opened, false otherwise.

◆ readEntry()

int readEntry ( char *  buf,
int  count 
)

Reads (and decompresses) data from the currently opened entry.

Parameters
bufThe buffer to read the data into.
countThe maximum number of bytes to read.
Returns
The number of bytes actually read, or -1 if there was an error.

◆ removeEntry()

bool removeEntry ( qint64  index)

Removes the entry at the specified index from the Zip archive.

Parameters
indexThe index.
Returns
true if the entry was successfully removed, false otherwise.

◆ renameEntry()

bool renameEntry ( qint64  index,
const QString &  newPath 
)

Changes the file path of the entry at the specified index in the Zip archive.

Parameters
indexThe index.
newPathThe new file path.
Returns
true if the entry was successfully updated, false otherwise.

◆ setArchiveComment()

bool setArchiveComment ( const QString &  comment)

Sets the Zip archive's comment.

Parameters
commentThe new comment.
Returns
true if the comment was successfully set, false otherwise.

◆ setEntryComment()

bool setEntryComment ( qint64  index,
const QString &  comment 
)

Sets the comment for the entry at the specified index in the Zip archive.

Parameters
indexThe index.
Returns
The comment.
true if the comment was successfully set, false otherwise.

Friends And Related Function Documentation

◆ ZipEntry

friend class ZipEntry
friend

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