org.kde.koala

Class KZip

public class KZip extends KArchive

This class implements a kioslave to access zip files from KDE. You can use it in IO_ReadOnly or in IO_WriteOnly mode, and it behaves just as expected. 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, 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 IO_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

UNKNOWN: A class for reading/writing zip archives.

Field Summary
static intDefaultExtraField
static intDeflateCompression
static intModificationTime
static intNoCompression
Describes the compression type for a given file in the Zip archive.
static intNoExtraField
Describes the contents of the "extra field" for a given file in the Zip archive.
Constructor Summary
protected KZip(Class dummy)
KZip(String filename)
Creates an instance that operates on the given filename. using the compression filter associated to given mimetype.
KZip(QIODeviceInterface dev)
Creates an instance that operates on the given device.
Method Summary
protected booleancloseArchive()
intcompression()
The current compression mode that will be used for new files.
voiddispose()
Delete the wrapped C++ instance ahead of finalize()
booleandoneWriting(int size)
Write data to a file that has been created using prepareWriting().
intextraField()
The current type of "extra field" that will be used for new files.
StringfileName()
The name of the zip file, as passed to the constructor.
protected voidfinalize()
Deletes the wrapped C++ instance
booleanisDisposed()
Has the wrapped C++ instance been deleted?
protected booleanopenArchive(int mode)
Opens the archive for reading.
booleanprepareWriting(String name, String user, String group, int size)
Alternative method for writing: call prepareWriting(), then feed the data in small chunks using writeData(), and call doneWriting() when done.
booleanprepareWriting(String name, String user, String group, int size, long perm, int atime, int mtime, int ctime)
protected booleanprepareWriting_impl(String name, String user, String group, int size, long perm, int atime, int mtime, int ctime)
voidsetCompression(int c)
Call this before writeFile or prepareWriting, to define whether the next files to be written should be compressed or not.
voidsetExtraField(int ef)
Call this before writeFile or prepareWriting, to define what the next file to be written should have in its extra field.
booleanwriteData(String data, int size)
Write data to a file that has been created using prepareWriting().
protected booleanwriteData_impl(String data, int size)
booleanwriteDir(String name, String user, String group)
booleanwriteFile(String name, String user, String group, int size, String data)
If an archive is opened for writing then you can add a new file using this function.
booleanwriteFile(String name, String user, String group, int size, long perm, int atime, int mtime, int ctime, String data)
booleanwriteSymLink(String name, String target, String user, String group, long perm, int atime, int mtime, int ctime)
protected booleanwriteSymLink_impl(String name, String target, String user, String group, long perm, int atime, int mtime, int ctime)

Field Detail

DefaultExtraField

public static final int DefaultExtraField

DeflateCompression

public static final int DeflateCompression

ModificationTime

public static final int ModificationTime

NoCompression

public static final int NoCompression
Describes the compression type for a given file in the Zip archive.

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

NoExtraField

public static final int NoExtraField
Describes the contents of the "extra field" for a given file in the Zip archive.

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

Constructor Detail

KZip

protected KZip(Class dummy)

KZip

public KZip(String 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")

UNKNOWN: Creates an instance that operates on the given filename.

KZip

public KZip(QIODeviceInterface dev)
Creates an instance that operates on the given device. The device can be compressed (KFilterDev) or not (QFile, etc.).

Parameters: dev the device to access

UNKNOWN: Do not assume that giving a QFile here will decompress the file, in case it's compressed! Creates an instance that operates on the given device.

Method Detail

closeArchive

protected boolean closeArchive()

compression

public int compression()
The current compression mode that will be used for new files.

Returns: the current compression mode

See Also: KZip

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

dispose

public void dispose()
Delete the wrapped C++ instance ahead of finalize()

doneWriting

public boolean doneWriting(int size)
Write data to a file that has been created using prepareWriting().

Parameters: size the size of the file

Returns: true if successful, false otherwise

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

extraField

public int extraField()
The current type of "extra field" that will be used for new files.

Returns: the current type of "extra field"

See Also: KZip

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

fileName

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

Returns: the zip's file name, or null if a QIODevice is used

UNKNOWN: The name of the zip file, as passed to the constructor.

finalize

protected void finalize()
Deletes the wrapped C++ instance

isDisposed

public boolean isDisposed()
Has the wrapped C++ instance been deleted?

openArchive

protected boolean openArchive(int mode)
Opens the archive for reading. Parses the directory listing of the archive and creates the KArchiveDirectory/KArchiveFile entries.

Parameters: mode the mode of the file

UNKNOWN: Opens the archive for reading.

prepareWriting

public boolean prepareWriting(String name, String user, String group, int size)
Alternative method for writing: call prepareWriting(), then feed the data in small chunks using writeData(), and call doneWriting() when done.

Parameters: name can include subdirs e.g. path/to/the/file user the user owning the file group the group owning the file size unused argument

Returns: true if successful, false otherwise

UNKNOWN: Alternative method for writing: call prepareWriting(), then feed the data in small chunks using writeData(), and call doneWriting() when done.

prepareWriting

public boolean prepareWriting(String name, String user, String group, int size, long perm, int atime, int mtime, int ctime)

prepareWriting_impl

protected boolean prepareWriting_impl(String name, String user, String group, int size, long perm, int atime, int mtime, int ctime)

setCompression

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

Parameters: c the new compression mode

See Also: KZip

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

setExtraField

public void setExtraField(int ef)
Call this before writeFile or prepareWriting, to define what the next file to be written should have in its extra field.

Parameters: ef the type of "extra field"

See Also: KZip

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

writeData

public boolean writeData(String data, int size)
Write data to a file that has been created using prepareWriting().

Parameters: data a pointer to the data size the size of the chunk

Returns: true if successful, false otherwise

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

writeData_impl

protected boolean writeData_impl(String data, int size)

UNKNOWN: for virtual_hook @short @internal for virtual_hook

writeDir

public boolean writeDir(String name, String user, String group)

UNKNOWN:

writeFile

public boolean writeFile(String name, String user, String group, int size, String data)
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 user the user owning the file group the group owning the file size the size of the file data a pointer to the data

Returns: true if successful, false otherwise

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

writeFile

public boolean writeFile(String name, String user, String group, int size, long perm, int atime, int mtime, int ctime, String data)

writeSymLink

public boolean writeSymLink(String name, String target, String user, String group, long perm, int atime, int mtime, int ctime)

writeSymLink_impl

protected boolean writeSymLink_impl(String name, String target, String user, String group, long perm, int atime, int mtime, int ctime)