\section{KZip Class Reference}
\label{classKZip}\index{KZip@{KZip}}
This class implements a kioslave to access zip files from {\bf KDE}. A class for reading/writing zip archives.  


{\tt \#include $<$kzip.h$>$}

Inheritance diagram for KZip:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=46pt]{classKZip__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for KZip:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=95pt]{classKZip__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Types}
\begin{CompactItemize}
\item 
enum {\bf Extra\-Field} \{ {\bf No\-Extra\-Field} =  0, 
{\bf Modification\-Time} =  1, 
{\bf Default\-Extra\-Field} =  1
 \}
\item 
enum {\bf Compression} \{ {\bf No\-Compression} =  0, 
{\bf Deflate\-Compression} =  1
 \}
\end{CompactItemize}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf KZip} (const {\bf QString} \&filename)
\item 
{\bf KZip} ({\bf QIODevice} $\ast$dev)
\item 
virtual {\bf $\sim$KZip} ()
\item 
{\bf QString} {\bf file\-Name} ()
\item 
void {\bf set\-Extra\-Field} ({\bf Extra\-Field} ef)
\item 
{\bf Extra\-Field} {\bf extra\-Field} () const 
\item 
void {\bf set\-Compression} ({\bf Compression} c)
\item 
{\bf Compression} {\bf compression} () const 
\item 
virtual bool {\bf write\-File} (const {\bf QString} \&name, const {\bf QString} \&user, const {\bf QString} \&group, uint size, const char $\ast$data)
\item 
virtual bool {\bf prepare\-Writing} (const {\bf QString} \&name, const {\bf QString} \&user, const {\bf QString} \&group, uint size)
\item 
bool {\bf write\-Sym\-Link} (const {\bf QString} \&name, const {\bf QString} \&target, const {\bf QString} \&user, const {\bf QString} \&group, mode\_\-t perm, time\_\-t atime, time\_\-t mtime, time\_\-t ctime)
\item 
bool {\bf prepare\-Writing} (const {\bf QString} \&name, const {\bf QString} \&user, const {\bf QString} \&group, uint size, mode\_\-t perm, time\_\-t atime, time\_\-t mtime, time\_\-t ctime)
\item 
bool {\bf write\-File} (const {\bf QString} \&name, const {\bf QString} \&user, const {\bf QString} \&group, uint size, mode\_\-t perm, time\_\-t atime, time\_\-t mtime, time\_\-t ctime, const char $\ast$data)
\item 
bool {\bf write\-Data} (const char $\ast$data, uint size)
\item 
virtual bool {\bf done\-Writing} (uint size)
\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
virtual bool {\bf open\-Archive} (int mode)
\item 
virtual bool {\bf close\-Archive} ()
\item 
virtual bool {\bf write\-Dir} (const {\bf QString} \&, const {\bf QString} \&, const {\bf QString} \&)
\item 
virtual void {\bf virtual\_\-hook} (int id, void $\ast$data)\label{classKZip_b3}

\item 
bool {\bf write\-Data\_\-impl} (const char $\ast$data, uint size)\label{classKZip_b4}

\item 
bool {\bf prepare\-Writing\_\-impl} (const {\bf QString} \&name, const {\bf QString} \&user, const {\bf QString} \&group, uint size, mode\_\-t perm, time\_\-t atime, time\_\-t mtime, time\_\-t ctime)\label{classKZip_b5}

\item 
bool {\bf write\-Sym\-Link\_\-impl} (const {\bf QString} \&name, const {\bf QString} \&target, const {\bf QString} \&user, const {\bf QString} \&group, mode\_\-t perm, time\_\-t atime, time\_\-t mtime, time\_\-t ctime)\label{classKZip_b6}

\end{CompactItemize}


\subsection{Detailed Description}
This class implements a kioslave to access zip files from {\bf KDE}. A class for reading/writing zip archives. 

You can use it in IO\_\-Read\-Only or in IO\_\-Write\-Only mode, and it behaves just as expected. It can also be used in IO\_\-Read\-Write 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\_\-Write\-Only 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 {\tt http://www.pkware.com/products/enterprise/white\_\-papers/appnote.html} 

\begin{Desc}
\item[Author:]Holger Schroeder $<${\tt holger-kde@holgis.net}$>$ \end{Desc}
\begin{Desc}
\item[Since:]3.1 \end{Desc}




Definition at line 53 of file kzip.h.

\subsection{Member Enumeration Documentation}
\index{KZip@{KZip}!ExtraField@{ExtraField}}
\index{ExtraField@{ExtraField}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf KZip::Extra\-Field}}\label{classKZip_w5}


Describes the contents of the \char`\"{}extra field\char`\"{} for a given file in the Zip archive. 

\begin{Desc}
\item[Enumeration values: ]\par
\begin{description}
\index{ModificationTime@{ModificationTime}!KZip@{KZip}}\index{KZip@{KZip}!ModificationTime@{ModificationTime}}\item[{\em 
Modification\-Time\label{classKZip_w5w1}
}]No extra field. \index{DefaultExtraField@{DefaultExtraField}!KZip@{KZip}}\index{KZip@{KZip}!DefaultExtraField@{DefaultExtraField}}\item[{\em 
Default\-Extra\-Field\label{classKZip_w5w2}
}]Modification time (\char`\"{}extended timestamp\char`\"{} header). \end{description}
\end{Desc}



Definition at line 89 of file kzip.h.\index{KZip@{KZip}!Compression@{Compression}}
\index{Compression@{Compression}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}enum {\bf KZip::Compression}}\label{classKZip_w6}


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

\begin{Desc}
\item[Enumeration values: ]\par
\begin{description}
\index{NoCompression@{NoCompression}!KZip@{KZip}}\index{KZip@{KZip}!NoCompression@{NoCompression}}\item[{\em 
No\-Compression\label{classKZip_w6w3}
}]Uncompressed. \index{DeflateCompression@{DeflateCompression}!KZip@{KZip}}\index{KZip@{KZip}!DeflateCompression@{DeflateCompression}}\item[{\em 
Deflate\-Compression\label{classKZip_w6w4}
}]Deflate compression method. \end{description}
\end{Desc}



Definition at line 112 of file kzip.h.

\subsection{Constructor \& Destructor Documentation}
\index{KZip@{KZip}!KZip@{KZip}}
\index{KZip@{KZip}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KZip::KZip (const {\bf QString} \& {\em filename})}\label{classKZip_a0}


Creates an instance that operates on the given filename. 

using the compression filter associated to given mimetype.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em filename}]is a local path (e.g. \char`\"{}/home/holger/myfile.zip\char`\"{}) \end{description}
\end{Desc}


Definition at line 335 of file kzip.cpp.\index{KZip@{KZip}!KZip@{KZip}}
\index{KZip@{KZip}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KZip::KZip ({\bf QIODevice} $\ast$ {\em dev})}\label{classKZip_a1}


Creates an instance that operates on the given device. 

The device can be compressed ({\bf KFilter\-Dev}{\rm (p.\,\pageref{classKFilterDev})}) or not ({\bf QFile}, etc.). WARNING: don't assume that giving a {\bf QFile} here will decompress the file, in case it's compressed! \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dev}]the device to access \end{description}
\end{Desc}


Definition at line 347 of file kzip.cpp.\index{KZip@{KZip}!~KZip@{$\sim$KZip}}
\index{~KZip@{$\sim$KZip}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KZip::$\sim${\bf KZip} ()\hspace{0.3cm}{\tt  [virtual]}}\label{classKZip_a2}


If the zip file is still opened, then it will be closed automatically by the destructor. 



Definition at line 354 of file kzip.cpp.

References KArchive::close(), KArchive::device(), QString::is\-Empty(), and KArchive::is\-Opened().

\subsection{Member Function Documentation}
\index{KZip@{KZip}!fileName@{fileName}}
\index{fileName@{fileName}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QString} KZip::file\-Name ()\hspace{0.3cm}{\tt  [inline]}}\label{classKZip_a3}


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

Null if you used the {\bf QIODevice} constructor. \begin{Desc}
\item[Returns:]the zip's file name, or null if a {\bf QIODevice} is used \end{Desc}


Definition at line 84 of file kzip.h.\index{KZip@{KZip}!setExtraField@{setExtraField}}
\index{setExtraField@{setExtraField}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KZip::set\-Extra\-Field ({\bf Extra\-Field} {\em ef})}\label{classKZip_a4}


Call this before write\-File or prepare\-Writing, to define what the next file to be written should have in its extra field. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ef}]the type of \char`\"{}extra field\char`\"{} \end{description}
\end{Desc}
\begin{Desc}
\item[See also:]{\bf extra\-Field()}{\rm (p.\,\pageref{classKZip_a5})} \end{Desc}


Definition at line 1350 of file kzip.cpp.\index{KZip@{KZip}!extraField@{extraField}}
\index{extraField@{extraField}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KZip::Extra\-Field} KZip::extra\-Field () const}\label{classKZip_a5}


The current type of \char`\"{}extra field\char`\"{} that will be used for new files. 

\begin{Desc}
\item[Returns:]the current type of \char`\"{}extra field\char`\"{} \end{Desc}
\begin{Desc}
\item[See also:]{\bf set\-Extra\-Field()}{\rm (p.\,\pageref{classKZip_a4})} \end{Desc}


Definition at line 1355 of file kzip.cpp.\index{KZip@{KZip}!setCompression@{setCompression}}
\index{setCompression@{setCompression}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KZip::set\-Compression ({\bf Compression} {\em c})}\label{classKZip_a6}


Call this before write\-File or prepare\-Writing, to define whether the next files to be written should be compressed or not. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em c}]the new compression mode \end{description}
\end{Desc}
\begin{Desc}
\item[See also:]{\bf compression()}{\rm (p.\,\pageref{classKZip_a7})} \end{Desc}


Definition at line 1340 of file kzip.cpp.

References No\-Compression.\index{KZip@{KZip}!compression@{compression}}
\index{compression@{compression}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KZip::Compression} KZip::compression () const}\label{classKZip_a7}


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

\begin{Desc}
\item[Returns:]the current compression mode \end{Desc}
\begin{Desc}
\item[See also:]{\bf set\-Compression()}{\rm (p.\,\pageref{classKZip_a6})} \end{Desc}


Definition at line 1345 of file kzip.cpp.

References Deflate\-Compression, and No\-Compression.\index{KZip@{KZip}!writeFile@{writeFile}}
\index{writeFile@{writeFile}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::write\-File (const {\bf QString} \& {\em name}, const {\bf QString} \& {\em user}, const {\bf QString} \& {\em group}, uint {\em size}, const char $\ast$ {\em data})\hspace{0.3cm}{\tt  [virtual]}}\label{classKZip_a8}


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. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]can include subdirs e.g. path/to/the/file \item[{\em user}]the user owning the file \item[{\em group}]the group owning the file \item[{\em size}]the size of the file \item[{\em data}]a pointer to the data \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]true if successful, false otherwise \end{Desc}


Reimplemented from {\bf KArchive} {\rm (p.\,\pageref{classKArchive_a12})}.

Definition at line 1001 of file kzip.cpp.

References KArchive::write\-File().\index{KZip@{KZip}!prepareWriting@{prepareWriting}}
\index{prepareWriting@{prepareWriting}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::prepare\-Writing (const {\bf QString} \& {\em name}, const {\bf QString} \& {\em user}, const {\bf QString} \& {\em group}, uint {\em size})\hspace{0.3cm}{\tt  [virtual]}}\label{classKZip_a9}


Alternative method for writing: call {\bf prepare\-Writing()}{\rm (p.\,\pageref{classKZip_a9})}, then feed the data in small chunks using {\bf write\-Data()}{\rm (p.\,\pageref{classKZip_a13})}, and call {\bf done\-Writing()}{\rm (p.\,\pageref{classKZip_a14})} when done. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]can include subdirs e.g. path/to/the/file \item[{\em user}]the user owning the file \item[{\em group}]the group owning the file \item[{\em size}]unused argument \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]true if successful, false otherwise \end{Desc}


Implements {\bf KArchive} {\rm (p.\,\pageref{classKArchive_a14})}.

Definition at line 1019 of file kzip.cpp.\index{KZip@{KZip}!writeSymLink@{writeSymLink}}
\index{writeSymLink@{writeSymLink}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::write\-Sym\-Link (const {\bf QString} \& {\em name}, const {\bf QString} \& {\em target}, const {\bf QString} \& {\em user}, const {\bf QString} \& {\em group}, mode\_\-t {\em perm}, time\_\-t {\em atime}, time\_\-t {\em mtime}, time\_\-t {\em ctime})}\label{classKZip_a10}


Writes a symbolic link to the archive if the archive must be opened for writing. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]name of symbolic link \item[{\em target}]target of symbolic link \item[{\em user}]the user that owns the directory \item[{\em group}]the group that owns the directory \item[{\em perm}]permissions of the directory \item[{\em atime}]time the file was last accessed \item[{\em mtime}]modification time of the file \item[{\em ctime}]creation time of the file \end{description}
\end{Desc}
\begin{Desc}
\item[Since:]3.2 // TODO(BIC) make virtual. For now it must be implemented by virtual\_\-hook. \end{Desc}


Reimplemented from {\bf KArchive} {\rm (p.\,\pageref{classKArchive_a11})}.

Definition at line 1247 of file kzip.cpp.

References KArchive::write\-Sym\-Link().\index{KZip@{KZip}!prepareWriting@{prepareWriting}}
\index{prepareWriting@{prepareWriting}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::prepare\-Writing (const {\bf QString} \& {\em name}, const {\bf QString} \& {\em user}, const {\bf QString} \& {\em group}, uint {\em size}, mode\_\-t {\em perm}, time\_\-t {\em atime}, time\_\-t {\em mtime}, time\_\-t {\em ctime})}\label{classKZip_a11}


Here's another way of writing a file into an archive: Call prepare\-Writing, then call {\bf write\-Data()}{\rm (p.\,\pageref{classKZip_a13})} as many times as wanted then call done\-Writing( total\-Size ). 

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.

This method also allows some file metadata to be set. However, depending on the archive type not all metadata might be regarded. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]the name of the file \item[{\em user}]the user that owns the file \item[{\em group}]the group that owns the file \item[{\em size}]the size of the file \item[{\em perm}]permissions of the file \item[{\em atime}]time the file was last accessed \item[{\em mtime}]modification time of the file \item[{\em ctime}]creation time of the file \end{description}
\end{Desc}
\begin{Desc}
\item[Since:]3.2 // TODO(BIC): make this virtual. For now use virtual hook. \end{Desc}


Reimplemented from {\bf KArchive} {\rm (p.\,\pageref{classKArchive_a15})}.

Definition at line 1028 of file kzip.cpp.

References KArchive::prepare\-Writing().\index{KZip@{KZip}!writeFile@{writeFile}}
\index{writeFile@{writeFile}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::write\-File (const {\bf QString} \& {\em name}, const {\bf QString} \& {\em user}, const {\bf QString} \& {\em group}, uint {\em size}, mode\_\-t {\em perm}, time\_\-t {\em atime}, time\_\-t {\em mtime}, time\_\-t {\em ctime}, const char $\ast$ {\em data})}\label{classKZip_a12}


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

If the file name is for example \char`\"{}mydir/test1\char`\"{} then the directory \char`\"{}mydir\char`\"{} is automatically appended first if that did not happen yet.

This method also allows some file metadata to be set. However, depending on the archive type not all metadata might be regarded. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]the name of the file \item[{\em user}]the user that owns the file \item[{\em group}]the group that owns the file \item[{\em size}]the size of the file \item[{\em perm}]permissions of the file \item[{\em atime}]time the file was last accessed \item[{\em mtime}]modification time of the file \item[{\em ctime}]creation time of the file \item[{\em data}]the data to write ({\tt size} bytes) \end{description}
\end{Desc}
\begin{Desc}
\item[Since:]3.2 // TODO(BIC): make virtual. For now use virtual hook \end{Desc}


Reimplemented from {\bf KArchive} {\rm (p.\,\pageref{classKArchive_a13})}.

Definition at line 1010 of file kzip.cpp.

References KArchive::write\-File().\index{KZip@{KZip}!writeData@{writeData}}
\index{writeData@{writeData}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::write\-Data (const char $\ast$ {\em data}, uint {\em size})}\label{classKZip_a13}


Write data to a file that has been created using {\bf prepare\-Writing()}{\rm (p.\,\pageref{classKZip_a9})}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em data}]a pointer to the data \item[{\em size}]the size of the chunk \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]true if successful, false otherwise \end{Desc}


Reimplemented from {\bf KArchive} {\rm (p.\,\pageref{classKArchive_a16})}.

Definition at line 1314 of file kzip.cpp.

References KArchive::write\-Data().\index{KZip@{KZip}!doneWriting@{doneWriting}}
\index{doneWriting@{doneWriting}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::done\-Writing (uint {\em size})\hspace{0.3cm}{\tt  [virtual]}}\label{classKZip_a14}


Write data to a file that has been created using {\bf prepare\-Writing()}{\rm (p.\,\pageref{classKZip_a9})}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em size}]the size of the file \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]true if successful, false otherwise \end{Desc}


Implements {\bf KArchive} {\rm (p.\,\pageref{classKArchive_a17})}.

Definition at line 1210 of file kzip.cpp.

References QIODevice::at(), KArchive::device(), Modification\-Time, and QIODevice::write\-Block().\index{KZip@{KZip}!openArchive@{openArchive}}
\index{openArchive@{openArchive}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::open\-Archive (int {\em mode})\hspace{0.3cm}{\tt  [protected, virtual]}}\label{classKZip_b0}


Opens the archive for reading. 

Parses the directory listing of the archive and creates the KArchive\-Directory/KArchive\-File entries. \begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em mode}]the mode of the file \end{description}
\end{Desc}


Implements {\bf KArchive} {\rm (p.\,\pageref{classKArchive_b1})}.

Definition at line 369 of file kzip.cpp.

References KArchive\-Directory::add\-Entry(), QIODevice::at(), QDir::clean\-Dir\-Path(), QFile::decode\-Name(), KArchive::device(), endl(), QString::ends\-With(), KArchive\-Directory::entry(), KArchive::find\-Or\-Create(), QString::find\-Rev(), QAscii\-Dict::insert(), KArchive\-Entry::is\-Directory(), QString::is\-Empty(), kd\-Debug(), kd\-Warning(), QString::left(), QString::length(), QString::mid(), No\-Compression, KArchive::open(), QIODevice::read\-Block(), KArchive::root\-Dir(), QAscii\-Dict::set\-Auto\-Delete(), and QIODevice::size().\index{KZip@{KZip}!closeArchive@{closeArchive}}
\index{closeArchive@{closeArchive}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KZip::close\-Archive ()\hspace{0.3cm}{\tt  [protected, virtual]}}\label{classKZip_b1}


Closes the archive. 



Implements {\bf KArchive} {\rm (p.\,\pageref{classKArchive_b2})}.

Definition at line 801 of file kzip.cpp.

References QIODevice::at(), QIODevice::close(), KArchive::device(), QFile::encode\-Name(), endl(), k\_\-funcinfo, kd\-Debug(), QCString::length(), KArchive::mode(), QIODevice::size(), and QIODevice::write\-Block().\index{KZip@{KZip}!writeDir@{writeDir}}
\index{writeDir@{writeDir}!KZip@{KZip}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KZip::write\-Dir (const {\bf QString} \&, const {\bf QString} \&, const {\bf QString} \&)\hspace{0.3cm}{\tt  [inline, protected, virtual]}}\label{classKZip_b2}


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

{\bf KArchive}{\rm (p.\,\pageref{classKArchive})} won't write one directory twice.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em name}]the name of the directory \item[{\em user}]the user that owns the directory \item[{\em group}]the group that owns the directory // TODO(BIC): make this a thin wrapper around // write\-Dir(name,user,group,perm,atime,mtime,ctime) // or elimitate it \end{description}
\end{Desc}


Implements {\bf KArchive} {\rm (p.\,\pageref{classKArchive_a9})}.

Definition at line 197 of file kzip.h.

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
kzip.h\item 
kzip.cpp\end{CompactItemize}
