# class KZip

###

Module | kio
Namespace |
Class | KZip
Inherits | KArchive

This class implements a kioslave to access zip files from KDE. 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 A class for reading/writing zip archives. Author Holger Schroeder <holger-kde@holgis.net>

### enums

- Compression { NoCompression, DeflateCompression }
- ExtraField { NoExtraField, ModificationTime, DefaultExtraField }

enum details

### methods

- KZip (filename)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  filename | QString |

  Creates an instance that operates on the given filename. using the compression filter associated to given mimetype.

  filename - is a local path (e.g. "/home/holger/myfile.zip")

- KZip (dev)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  dev | QIODevice |

  Creates an instance that operates on the given device. The device can be compressed (KFilterDev) or not (QFile, etc.). Do not assume that giving a QFile here will decompress the file, in case it's compressed!

  dev - the device to access

- closeArchive ( )

  returns bool

  Closes the archive

- compression ( )

  returns KZip.Compression

  The current compression mode that will be used for new files. Returns the current compression mode

  See also setCompression()

- doFinishWriting (size)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  size | qint64 |

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

  size - the size of the file Returns true if successful, false otherwise

- doPrepareWriting (name, user, group, size, perm, atime, mtime, ctime)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  name | QString |
  user | QString |
  group | QString |
  size | qint64 |
  perm | mode_t |
  atime | time_t |
  mtime | time_t |
  ctime | time_t |

  Reimplemented from KArchive

- doWriteDir (name, user, group, perm, atime, mtime, ctime)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  name | QString |
  user | QString |
  group | QString |
  perm | mode_t |
  atime | time_t |
  mtime | time_t |
  ctime | time_t |

  Internal Not needed for zip

- doWriteSymLink (name, target, user, group, perm, atime, mtime, ctime)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  name | QString |
  target | QString |
  user | QString |
  group | QString |
  perm | mode_t |
  atime | time_t |
  mtime | time_t |
  ctime | time_t |

  Reimplemented from KArchive

- extraField ( )

  returns KZip.ExtraField

  The current type of "extra field" that will be used for new files. Returns the current type of "extra field"

  See also setExtraField()

- openArchive (mode)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  mode | QIODevice.OpenMode |

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

  mode - the mode of the file

- setCompression (c)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  c | KZip.Compression |

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

  c - the new compression mode

  See also compression()

- setExtraField (ef)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  ef | KZip.ExtraField |

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

  ef - the type of "extra field"

  See also extraField()

- virtual_hook (id, data)

  returns Nothing
  Not implemented

  Argument | Type | Default
  --- | --- | ---
  id | int |
  data | void |

- writeData (data, size)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  data | char |
  size | qint64 |

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

  data - a pointer to the data

  size - the size of the chunk Returns true if successful, false otherwise

### enums - detail

- Compression { NoCompression, DeflateCompression }

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

  | NoCompression | - 0 | - |
  | DeflateCompression | - 1 | - |

- ExtraField { NoExtraField, ModificationTime, DefaultExtraField }

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

  | NoExtraField | - 0 | - |
  | ModificationTime | - 1 | - |
  | DefaultExtraField | - 1 | - |