KZip

Inheritance diagram for KZip:

Public Types

enum  Compression { NoCompression = 0, DeflateCompression = 1 }
 
enum  ExtraField { NoExtraField = 0, ModificationTime = 1, DefaultExtraField = 1 }
 

Public Member Functions

 KZip (const QString &filename)
 
 KZip (QIODevice *dev)
 
virtual ~KZip ()
 
Compression compression () const
 
ExtraField extraField () const
 
void setCompression (Compression c)
 
void setExtraField (ExtraField ef)
 
bool writeData (const char *data, qint64 size) override
 
- Public Member Functions inherited from KArchive
bool addLocalDirectory (const QString &path, const QString &destName)
 
bool addLocalFile (const QString &fileName, const QString &destName)
 
virtual bool close ()
 
QIODevicedevice () const
 
const KArchiveDirectorydirectory () const
 
QString errorString () const
 
QString fileName () const
 
bool finishWriting (qint64 size)
 
bool isOpen () const
 
QIODevice::OpenMode mode () const
 
virtual bool open (QIODevice::OpenMode mode)
 
bool prepareWriting (const QString &name, const QString &user, const QString &group, qint64 size, mode_t perm=0100644, const QDateTime &atime=QDateTime(), const QDateTime &mtime=QDateTime(), const QDateTime &ctime=QDateTime())
 
bool writeDir (const QString &name, const QString &user=QString(), const QString &group=QString(), mode_t perm=040755, const QDateTime &atime=QDateTime(), const QDateTime &mtime=QDateTime(), const QDateTime &ctime=QDateTime())
 
bool writeFile (const QString &name, const QString &user, const QString &group, const char *data, qint64 size, mode_t perm=0100644, const QDateTime &atime=QDateTime(), const QDateTime &mtime=QDateTime(), const QDateTime &ctime=QDateTime())
 
bool writeFile (const QString &name, const QByteArray &data, mode_t perm=0100644, const QString &user=QString(), const QString &group=QString(), const QDateTime &atime=QDateTime(), const QDateTime &mtime=QDateTime(), const QDateTime &ctime=QDateTime())
 
bool writeSymLink (const QString &name, const QString &target, const QString &user=QString(), const QString &group=QString(), mode_t perm=0120755, const QDateTime &atime=QDateTime(), const QDateTime &mtime=QDateTime(), const QDateTime &ctime=QDateTime())
 

Protected Member Functions

bool closeArchive () override
 
bool doFinishWriting (qint64 size) override
 
bool doPrepareWriting (const QString &name, const QString &user, const QString &group, qint64 size, mode_t perm, const QDateTime &atime, const QDateTime &mtime, const QDateTime &creationTime) override
 
bool doWriteDir (const QString &name, const QString &user, const QString &group, mode_t perm, const QDateTime &atime, const QDateTime &mtime, const QDateTime &ctime) override
 
bool doWriteSymLink (const QString &name, const QString &target, const QString &user, const QString &group, mode_t perm, const QDateTime &atime, const QDateTime &mtime, const QDateTime &ctime) override
 
bool openArchive (QIODevice::OpenMode mode) override
 
void virtual_hook (int id, void *data) override
 
- Protected Member Functions inherited from KArchive
 KArchive (const QString &fileName)
 
 KArchive (QIODevice *dev)
 
virtual bool createDevice (QIODevice::OpenMode mode)
 
KArchiveDirectoryfindOrCreate (const QString &path)
 
virtual KArchiveDirectoryrootDir ()
 
void setDevice (QIODevice *dev)
 
void setErrorString (const QString &errorStr)
 
void setRootDir (KArchiveDirectory *rootDir)
 

Detailed Description

A class for reading / writing zip archives.

You can use it in QIODevice::ReadOnly or in QIODevice::WriteOnly mode, and it behaves just as expected. It can also be used in QIODevice::ReadWrite mode, in this case one can append files to an existing zip archive. When you append new files, which are not yet in the zip, it works as expected, i.e. the files are appended at the end. When you append a file, which is already in the file, the reference to the old file is dropped and the new one is added to the zip - but the old data from the file itself is not deleted, it is still in the zipfile. So when you want to have a small and garbage-free zipfile, just read the contents of the appended zip file and write it to a new one in QIODevice::WriteOnly mode. This is especially important when you don't want to leak information of how intermediate versions of files in the zip were looking.

For more information on the zip fileformat go to http://www.pkware.com/products/enterprise/white_papers/appnote.html

Author
Holger Schroeder holge[email protected]r-kd[email protected][email protected][email protected]gis.[email protected]net

Definition at line 37 of file kzip.h.

Member Enumeration Documentation

Describes the compression type for a given file in the Zip archive.

Enumerator
NoCompression 

Uncompressed.

DeflateCompression 

Deflate compression method.

Definition at line 92 of file kzip.h.

Describes the contents of the "extra field" for a given file in the Zip archive.

Enumerator
NoExtraField 

No extra field.

ModificationTime 

Modification time ("extended timestamp" header)

Definition at line 68 of file kzip.h.

Constructor & Destructor Documentation

KZip::KZip ( const QString filename)

Creates an instance that operates on the given filename.

using the compression filter associated to given mimetype.

Parameters
filenameis a local path (e.g. "/home/holger/myfile.zip")

Definition at line 406 of file kzip.cpp.

KZip::KZip ( QIODevice dev)

Creates an instance that operates on the given device.

The device can be compressed (KFilterDev) or not (QFile, etc.).

Warning
Do not assume that giving a QFile here will decompress the file, in case it's compressed!
Parameters
devthe device to access

Definition at line 412 of file kzip.cpp.

KZip::~KZip ( )
virtual

If the zip file is still opened, then it will be closed automatically by the destructor.

Definition at line 418 of file kzip.cpp.

Member Function Documentation

bool KZip::closeArchive ( )
overrideprotectedvirtual

Closes the archive.

Implements KArchive.

Definition at line 823 of file kzip.cpp.

KZip::Compression KZip::compression ( ) const

The current compression mode that will be used for new files.

Returns
the current compression mode
See also
setCompression()

Definition at line 1330 of file kzip.cpp.

bool KZip::doFinishWriting ( qint64  size)
overrideprotectedvirtual

Write data to a file that has been created using prepareWriting().

Parameters
sizethe size of the file
Returns
true if successful, false otherwise

Implements KArchive.

Definition at line 1226 of file kzip.cpp.

bool KZip::doPrepareWriting ( const QString name,
const QString user,
const QString group,
qint64  size,
mode_t  perm,
const QDateTime atime,
const QDateTime mtime,
const QDateTime creationTime 
)
overrideprotectedvirtual

Reimplemented from KArchive.

Implements KArchive.

Definition at line 1041 of file kzip.cpp.

bool KZip::doWriteDir ( const QString name,
const QString user,
const QString group,
mode_t  perm,
const QDateTime atime,
const QDateTime mtime,
const QDateTime ctime 
)
overrideprotectedvirtual

Reimplemented from KArchive.

Implements KArchive.

Definition at line 1028 of file kzip.cpp.

bool KZip::doWriteSymLink ( const QString name,
const QString target,
const QString user,
const QString group,
mode_t  perm,
const QDateTime atime,
const QDateTime mtime,
const QDateTime ctime 
)
overrideprotectedvirtual

Reimplemented from KArchive.

Implements KArchive.

Definition at line 1264 of file kzip.cpp.

KZip::ExtraField KZip::extraField ( ) const

The current type of "extra field" that will be used for new files.

Returns
the current type of "extra field"
See also
setExtraField()

Definition at line 1340 of file kzip.cpp.

bool KZip::openArchive ( QIODevice::OpenMode  mode)
overrideprotectedvirtual

Opens the archive for reading.

Parses the directory listing of the archive and creates the KArchiveDirectory/KArchiveFile entries.

Parameters
modethe mode of the file

Implements KArchive.

Definition at line 427 of file kzip.cpp.

void KZip::setCompression ( Compression  c)

Call this before writeFile or prepareWriting, to define whether the next files to be written should be compressed or not.

Parameters
cthe new compression mode
See also
compression()

Definition at line 1325 of file kzip.cpp.

void KZip::setExtraField ( ExtraField  ef)

Call this before writeFile or prepareWriting, to define what the next file to be written should have in its extra field.

Parameters
efthe type of "extra field"
See also
extraField()

Definition at line 1335 of file kzip.cpp.

bool KZip::writeData ( const char *  data,
qint64  size 
)
overridevirtual

Write data to a file that has been created using prepareWriting().

Parameters
dataa pointer to the data
sizethe size of the chunk
Returns
true if successful, false otherwise

Reimplemented from KArchive.

Definition at line 1299 of file kzip.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Nov 30 2020 23:03:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.