• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDECore

Public Types | Public Member Functions | Protected Member Functions

KZip Class Reference

A class for reading / writing zip archives. More...

#include <kzip.h>

Inheritance diagram for KZip:
Inheritance graph
[legend]

List of all members.

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)
virtual bool writeData (const char *data, qint64 size)

Protected Member Functions

virtual bool closeArchive ()
virtual bool doFinishWriting (qint64 size)
virtual bool doPrepareWriting (const QString &name, const QString &user, const QString &group, qint64 size, mode_t perm, time_t atime, time_t mtime, time_t ctime)
virtual bool doWriteDir (const QString &name, const QString &user, const QString &group, mode_t perm, time_t atime, time_t mtime, time_t ctime)
virtual bool doWriteSymLink (const QString &name, const QString &target, const QString &user, const QString &group, mode_t perm, time_t atime, time_t mtime, time_t ctime)
virtual bool openArchive (QIODevice::OpenMode mode)
virtual void virtual_hook (int id, void *data)

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 <holger-kde@holgis.net>

Definition at line 45 of file kzip.h.


Member Enumeration Documentation

enum KZip::Compression

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

Enumerator:
NoCompression 

Uncompressed.

DeflateCompression 

Deflate compression method.

Definition at line 97 of file kzip.h.

enum KZip::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)

DefaultExtraField 

Definition at line 74 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 313 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 318 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 323 of file kzip.cpp.


Member Function Documentation

bool KZip::closeArchive ( ) [protected, virtual]

Closes the archive.

Implements KArchive.

Definition at line 788 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 1255 of file kzip.cpp.

bool KZip::doFinishWriting ( qint64  size) [protected, virtual]

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

bool KZip::doPrepareWriting ( const QString &  name,
const QString &  user,
const QString &  group,
qint64  size,
mode_t  perm,
time_t  atime,
time_t  mtime,
time_t  ctime 
) [protected, virtual]

Reimplemented from KArchive.

Implements KArchive.

Definition at line 989 of file kzip.cpp.

bool KZip::doWriteDir ( const QString &  name,
const QString &  user,
const QString &  group,
mode_t  perm,
time_t  atime,
time_t  mtime,
time_t  ctime 
) [protected, virtual]

Reimplemented from KArchive.

Implements KArchive.

Definition at line 978 of file kzip.cpp.

bool KZip::doWriteSymLink ( const QString &  name,
const QString &  target,
const QString &  user,
const QString &  group,
mode_t  perm,
time_t  atime,
time_t  mtime,
time_t  ctime 
) [protected, virtual]

Reimplemented from KArchive.

Implements KArchive.

Definition at line 1196 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 1265 of file kzip.cpp.

bool KZip::openArchive ( QIODevice::OpenMode  mode) [protected, virtual]

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 331 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 1250 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 1260 of file kzip.cpp.

void KZip::virtual_hook ( int  id,
void *  data 
) [protected, virtual]

Reimplemented from KArchive.

Definition at line 1228 of file kzip.cpp.

bool KZip::writeData ( const char *  data,
qint64  size 
) [virtual]

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


The documentation for this class was generated from the following files:
  • kzip.h
  • kzip.cpp

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal