kio Library API Documentation

KZip Class Reference

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

#include <kzip.h>

Inheritance diagram for KZip:

KArchive List of all members.

Public Types

enum  Compression { NoCompression = 0, DeflateCompression = 1 }

Public Member Functions

 KZip (const QString &filename)
 Creates an instance that operates on the given filename.

 KZip (QIODevice *dev)
 Creates an instance that operates on the given device.

virtual ~KZip ()
 If the zip file is still opened, then it will be closed automatically by the destructor.

QString fileName ()
 The name of the zip file, as passed to the constructor Null if you used the QIODevice constructor.

void setCompression (Compression c)
 Call this before writeFile or prepareWriting, to define whether the next files to be written should be compressed or not.

Compression compression () const
virtual bool writeFile (const QString &name, const QString &user, const QString &group, uint size, const char *data)
 If an archive is opened for writing then you can add a new file using this function.

virtual bool prepareWriting (const QString &name, const QString &user, const QString &group, uint size)
 Alternative method: call prepareWriting, writeData in small chunks, doneWriting.

bool writeData (const char *data, uint size)
virtual bool doneWriting (uint size)
 Call doneWriting after writing the data.


Protected Member Functions

virtual bool openArchive (int mode)
 Opens the archive for reading.

virtual bool closeArchive ()
 Closes the archive.

virtual bool writeDir (const QString &, const QString &, const QString &)
 If an archive is opened for writing then you can add new directories using this function.

virtual void virtual_hook (int id, void *data)

Detailed Description

A class for reading/writing zip archives.

Author:
Holger Schroeder <holger-kde@holgis.net>
This class implements a kioslave to acces ZIP files from KDE. you can use it in IO_ReadOnly or in IO_WriteOnly mode, and it behaves just as expected (i hope ;-) ). It can also be used in IO_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, they 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 garbagefree zipfile, just read the contents of the appended zipfile and write it to a new one in IO_WriteOnly mode. exspecially take care of this, 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/support/appnote.html .
Since:
3.1

Definition at line 54 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:
filename is a local path (e.g. "/home/holger/myfile.zip")

Definition at line 120 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: don't assume that giving a QFile here will decompress the file, in case it's compressed!

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

References KArchive::close(), KArchive::device(), QString::isEmpty(), and KArchive::isOpened().


Member Function Documentation

QString KZip::fileName  )  [inline]
 

The name of the zip file, as passed to the constructor Null if you used the QIODevice constructor.

Definition at line 83 of file kzip.h.

Referenced by prepareWriting().

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.

Definition at line 762 of file kzip.cpp.

bool KZip::writeFile const QString name,
const QString user,
const QString group,
uint  size,
const char *  data
[virtual]
 

If an archive is opened for writing then you can add a new file using this function.

This method takes the whole data at once.

Parameters:
name can include subdirs e.g. path/to/the/file

Reimplemented from KArchive.

Definition at line 553 of file kzip.cpp.

References QIODevice::at(), KArchive::device(), doneWriting(), KStdAccel::name(), and prepareWriting().

bool KZip::prepareWriting const QString name,
const QString user,
const QString group,
uint  size
[virtual]
 

Alternative method: call prepareWriting, writeData in small chunks, doneWriting.

Parameters:
size unused

Implements KArchive.

Definition at line 580 of file kzip.cpp.

References KArchiveDirectory::addEntry(), QPtrListIterator::current(), KFilterDev::device(), KArchive::device(), QFile::encodeName(), fileName(), KArchive::findOrCreate(), QString::findRev(), KArchive::isOpened(), QString::left(), QCString::length(), QString::length(), QString::mid(), KArchive::mode(), KStdAccel::name(), KArchive::rootDir(), and QIODevice::writeBlock().

Referenced by writeFile().

bool KZip::doneWriting uint  size  )  [virtual]
 

Call doneWriting after writing the data.

See also:
prepareWriting

Implements KArchive.

Definition at line 710 of file kzip.cpp.

References QIODevice::at(), and KArchive::device().

Referenced by writeFile().

bool KZip::openArchive int  mode  )  [protected, virtual]
 

Opens the archive for reading.

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

Implements KArchive.

Definition at line 147 of file kzip.cpp.

References KArchiveDirectory::addEntry(), QIODevice::at(), QDir::cleanDirPath(), KArchive::device(), QString::endsWith(), KArchiveDirectory::entry(), KArchive::findOrCreate(), QString::findRev(), QString::fromLocal8Bit(), KArchiveEntry::isDirectory(), QString::isEmpty(), QString::left(), QString::length(), QString::mid(), KStdAccel::name(), QIODevice::readBlock(), and KArchive::rootDir().

bool KZip::closeArchive  )  [protected, virtual]
 

Closes the archive.

Called by close.

Implements KArchive.

Definition at line 392 of file kzip.cpp.

References QIODevice::at(), QPtrListIterator::current(), KArchive::device(), QFile::encodeName(), QCString::length(), KArchive::mode(), QPtrListIterator::toFirst(), and QIODevice::writeBlock().

virtual bool KZip::writeDir const QString ,
const QString ,
const QString
[inline, protected, virtual]
 

If an archive is opened for writing then you can add new directories using this function.

KArchive won't write one directory twice.

Implements KArchive.

Definition at line 122 of file kzip.h.


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:15:38 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001