KZip

Search for usage in LXR

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)
 
 ~KZip () override
 
Compression compression () const
 
ExtraField extraField () const
 
void setCompression (Compression c)
 
void setExtraField (ExtraField ef)
 
- 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 writeData (const char *data, qint64 size)
 
bool writeData (QByteArrayView data)
 
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, QByteArrayView 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 doWriteData (const char *data, qint64 size) 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.nosp@m.r-kd.nosp@m.e@hol.nosp@m.gis..nosp@m.net

Definition at line 37 of file kzip.h.

Member Enumeration Documentation

◆ Compression

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.

◆ ExtraField

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() [1/2]

KZip::KZip ( const QString & filename)
explicit

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 413 of file kzip.cpp.

◆ KZip() [2/2]

KZip::KZip ( QIODevice * dev)
explicit

Creates an instance that operates on the given device.

The device can be compressed (KCompressionDevice) 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 419 of file kzip.cpp.

◆ ~KZip()

KZip::~KZip ( )
override

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

Definition at line 425 of file kzip.cpp.

Member Function Documentation

◆ closeArchive()

bool KZip::closeArchive ( )
overrideprotectedvirtual

Closes the archive.

Implements KArchive.

Definition at line 821 of file kzip.cpp.

◆ compression()

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 1334 of file kzip.cpp.

◆ doFinishWriting()

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 1229 of file kzip.cpp.

◆ doPrepareWriting()

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 1033 of file kzip.cpp.

◆ doWriteData()

bool KZip::doWriteData ( const char * data,
qint64 size )
overrideprotectedvirtual

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 1305 of file kzip.cpp.

◆ doWriteDir()

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 1015 of file kzip.cpp.

◆ doWriteSymLink()

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 1265 of file kzip.cpp.

◆ extraField()

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 1344 of file kzip.cpp.

◆ openArchive()

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 434 of file kzip.cpp.

◆ setCompression()

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 1329 of file kzip.cpp.

◆ setExtraField()

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 1339 of file kzip.cpp.

◆ virtual_hook()

void KZip::virtual_hook ( int id,
void * data )
overrideprotectedvirtual

Reimplemented from KArchive.

Definition at line 1300 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-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.