| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# KArchive Class Reference

generic class for reading/writing archives More...

`#include <karchive.h>`

Inheritance diagram for KArchive:

[legend]
Collaboration diagram for KArchive:

[legend]
List of all members.

## Public Member Functions
virtual bool | open (int mode)
| Opens the archive for reading or writing.
virtual void | close ()
| Closes the archive.
bool | isOpened () const
int | mode () const
QIODevice * | device () const
| The underlying device.
const KArchiveDirectory * | directory () const
| If an archive is opened for reading, then the contents of the archive can be accessed via this function.
virtual bool | writeDir (const QString &name, const QString &user, const QString &group)=0
| If an archive is opened for writing then you can add new directories using this function.
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)=0
| Here's another way of writing a file into an archive: Call prepareWriting, then call device()->writeBlock() (for tar files) or writeData (for zip files) [NEW VIRTUAL METHOD NEEDED] as many times as wanted then call doneWriting( totalSize ) For tar.gz files, you need to know the size before hand, it is needed in the header! For zip files, size isn't used.
virtual bool | doneWriting (uint size)=0
| Call doneWriting after writing the data.
## Protected Member Functions
| KArchive (QIODevice *dev)
| Base constructor (protected since this is a pure virtual class).
virtual bool | openArchive (int mode)=0
| Opens an archive for reading or writing.
virtual bool | closeArchive ()=0
| Closes the archive.
virtual KArchiveDirectory * | rootDir ()
| Retrieves or create the root directory.
KArchiveDirectory * | findOrCreate (const QString &path)
| Ensures that `path` exists, create otherwise.
void | setDevice (QIODevice *dev)
void | setRootDir (KArchiveDirectory *rootDir)
virtual void | virtual_hook (int id, void *data)

## Detailed Description

generic class for reading/writing archives

Author:
  David Faure <faure@kde.org>

Definition at line 38 of file karchive.h.

## Constructor & Destructor Documentation

KArchive::KArchive | ( | QIODevice * | dev | ) | `[protected]`

  | Base constructor (protected since this is a pure virtual class). Parameters:
  dev | the I/O device where the archive reads its data Note that this can be a file, but also a data buffer, a compression filter, etc.
Definition at line 69 of file karchive.cpp.

## Member Function Documentation

bool KArchive::open | ( | int | mode | ) | `[virtual]`

  | Opens the archive for reading or writing. Parameters:
  mode | may be IO_ReadOnly or IO_WriteOnly Inherited classes might want to reimplement openArchive instead.
See also: close Definition at line 85 of file karchive.cpp. References close(), QIODevice::open(), and openArchive().

void KArchive::close | ( |  | ) | `[virtual]`

| Closes the archive. Inherited classes might want to reimplement closeArchive instead. See also: open Definition at line 105 of file karchive.cpp. References QIODevice::close(), and closeArchive(). Referenced by open(), KAr::~KAr(), KTar::~KTar(), and KZip::~KZip().

bool KArchive::isOpened | ( |  | ) | const`[inline]`

| Returns: true if the archive is opened Definition at line 70 of file karchive.h. Referenced by KZip::prepareWriting(), KTar::prepareWriting(), KTar::setOrigFileName(), KTar::writeDir(), KAr::~KAr(), KTar::~KTar(), and KZip::~KZip().

int KArchive::mode | ( |  | ) | const`[inline]`

| Returns: the mode in which the archive was opened (IO_ReadOnly or IO_WriteOnly) Definition at line 75 of file karchive.h. Referenced by KZip::closeArchive(), KZip::prepareWriting(), KTar::prepareWriting(), KTar::setOrigFileName(), and KTar::writeDir().

QIODevice* KArchive::device | ( |  | ) | const`[inline]`

| The underlying device. Definition at line 80 of file karchive.h. Referenced by KZip::closeArchive(), KArchiveFile::data(), KZip::doneWriting(), KTar::doneWriting(), KZip::openArchive(), KTar::openArchive(), KAr::openArchive(), KZip::prepareWriting(), KTar::prepareWriting(), KTar::setOrigFileName(), KTar::writeDir(), KZip::writeFile(), writeFile(), KAr::~KAr(), KTar::~KTar(), and KZip::~KZip().

const KArchiveDirectory * KArchive::directory | ( |  | ) | const

| If an archive is opened for reading, then the contents of the archive can be accessed via this function. Definition at line 120 of file karchive.cpp.

virtual bool KArchive::writeDir | ( | const QString & | name,
|  | const QString & | user,
|  | const QString & | group
| ) | `[pure virtual]`

| If an archive is opened for writing then you can add new directories using this function. KArchive won't write one directory twice. Implemented in KAr, KTar, and KZip.

bool KArchive::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. If the file name is for example "mydir/test1" then the directory "mydir" is automatically appended first if that did not happen yet. Reimplemented in KZip. Definition at line 126 of file karchive.cpp. References device(), doneWriting(), KStdAccel::name(), prepareWriting(), and QIODevice::writeBlock().

virtual bool KArchive::prepareWriting | ( | const QString & | name,
|  | const QString & | user,
|  | const QString & | group,
|  | uint | size
| ) | `[pure virtual]`

| Here's another way of writing a file into an archive: Call prepareWriting, then call device()->writeBlock() (for tar files) or writeData (for zip files) [NEW VIRTUAL METHOD NEEDED] as many times as wanted then call doneWriting( totalSize ) For tar.gz files, you need to know the size before hand, it is needed in the header! For zip files, size isn't used. Implemented in KAr, KTar, and KZip. Referenced by writeFile().

virtual bool KArchive::doneWriting | ( | uint | size | ) | `[pure virtual]`

| Call doneWriting after writing the data. See also: prepareWriting Implemented in KAr, KTar, and KZip. Referenced by writeFile().

virtual bool KArchive::openArchive | ( | int | mode | ) | `[protected, pure virtual]`

| Opens an archive for reading or writing. Called by open. Implemented in KAr, KTar, and KZip. Referenced by open().

virtual bool KArchive::closeArchive | ( |  | ) | `[protected, pure virtual]`

| Closes the archive. Called by close. Implemented in KAr, KTar, and KZip. Referenced by close().

KArchiveDirectory * KArchive::rootDir | ( |  | ) | `[protected, virtual]`

| Retrieves or create the root directory. The default implementation assumes that openArchive() did the parsing, so it creates a dummy rootdir if none was set (write mode, or no '/' in the archive). Reimplement this to provide parsing/listing on demand. Definition at line 151 of file karchive.cpp. References QFile::decodeName(), QString::fromLatin1(), and QString::number(). Referenced by findOrCreate(), KZip::openArchive(), KTar::openArchive(), KAr::openArchive(), and KZip::prepareWriting().

KArchiveDirectory * KArchive::findOrCreate | ( | const QString & | path | ) | `[protected]`

| Ensures that `path` exists, create otherwise. This handles e.g. tar files missing directory entries, like mico-2.3.0.tar.gz :) Definition at line 166 of file karchive.cpp. References KArchiveDirectory::addEntry(), KArchiveDirectory::entry(), QString::findRev(), KArchiveEntry::isDirectory(), QString::left(), QString::mid(), and rootDir(). Referenced by KZip::openArchive(), KTar::openArchive(), and KZip::prepareWriting().

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

- karchive.h
- karchive.cpp

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:14:58 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001