\section{KArchive Class Reference}
\label{classKArchive}\index{KArchive@{KArchive}}
generic class for reading/writing archives  


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

Inheritance diagram for KArchive:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=88pt]{classKArchive__inherit__graph}
\end{center}
\end{figure}
Collaboration diagram for KArchive:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=57pt]{classKArchive__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
virtual bool {\bf open} (int mode)
\begin{CompactList}\small\item\em Opens the archive for reading or writing. \item\end{CompactList}\item 
virtual void {\bf close} ()
\begin{CompactList}\small\item\em Closes the archive. \item\end{CompactList}\item 
bool {\bf is\-Opened} () const 
\item 
int {\bf mode} () const 
\item 
{\bf QIODevice} $\ast$ {\bf device} () const 
\begin{CompactList}\small\item\em The underlying device. \item\end{CompactList}\item 
const  {\bf KArchive\-Directory} $\ast$ {\bf directory} () const 
\begin{CompactList}\small\item\em If an archive is opened for reading, then the contents of the archive can be accessed via this function. \item\end{CompactList}\item 
virtual bool {\bf write\-Dir} (const  {\bf QString} \&name, const  {\bf QString} \&user, const  {\bf QString} \&group)=0
\begin{CompactList}\small\item\em If an archive is opened for writing then you can add new directories using this function. \item\end{CompactList}\item 
virtual bool {\bf write\-File} (const  {\bf QString} \&name, const  {\bf QString} \&user, const  {\bf QString} \&group, uint size, const  char $\ast$data)
\begin{CompactList}\small\item\em If an archive is opened for writing then you can add a new file using this function. \item\end{CompactList}\item 
virtual bool {\bf prepare\-Writing} (const  {\bf QString} \&name, const  {\bf QString} \&user, const  {\bf QString} \&group, uint size)=0
\begin{CompactList}\small\item\em Here's another way of writing a file into an archive: Call {\bf prepare\-Writing}{\rm (p.\,\pageref{classKArchive_a9})}, then call {\bf device()}{\rm (p.\,\pageref{classKArchive_a5})}-$>$write\-Block() (for tar files) or write\-Data (for zip files) [NEW VIRTUAL METHOD NEEDED] as many times as wanted then call {\bf done\-Writing}{\rm (p.\,\pageref{classKArchive_a10})}( 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. \item\end{CompactList}\item 
virtual bool {\bf done\-Writing} (uint size)=0
\begin{CompactList}\small\item\em Call {\bf done\-Writing}{\rm (p.\,\pageref{classKArchive_a10})} after writing the data. \item\end{CompactList}\end{CompactItemize}
\subsection*{Protected Member Functions}
\begin{CompactItemize}
\item 
{\bf KArchive} ({\bf QIODevice} $\ast$dev)
\begin{CompactList}\small\item\em Base constructor (protected since this is a pure virtual class). \item\end{CompactList}\item 
virtual bool {\bf open\-Archive} (int mode)=0
\begin{CompactList}\small\item\em Opens an archive for reading or writing. \item\end{CompactList}\item 
virtual bool {\bf close\-Archive} ()=0
\begin{CompactList}\small\item\em Closes the archive. \item\end{CompactList}\item 
virtual {\bf KArchive\-Directory} $\ast$ {\bf root\-Dir} ()
\begin{CompactList}\small\item\em Retrieves or create the root directory. \item\end{CompactList}\item 
{\bf KArchive\-Directory} $\ast$ {\bf find\-Or\-Create} (const  {\bf QString} \&path)
\begin{CompactList}\small\item\em Ensures that {\tt path} exists, create otherwise. \item\end{CompactList}\item 
void {\bf set\-Device} ({\bf QIODevice} $\ast$dev)\label{classKArchive_b5}

\item 
void {\bf set\-Root\-Dir} ({\bf KArchive\-Directory} $\ast$root\-Dir)\label{classKArchive_b6}

\item 
virtual void {\bf virtual\_\-hook} (int id, void $\ast$data)\label{classKArchive_b7}

\end{CompactItemize}


\subsection{Detailed Description}
generic class for reading/writing archives 

\begin{Desc}
\item[Author:]David Faure $<${\tt faure@kde.org}$>$ \end{Desc}




Definition at line 38 of file karchive.h.

\subsection{Constructor \& Destructor Documentation}
\index{KArchive@{KArchive}!KArchive@{KArchive}}
\index{KArchive@{KArchive}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}KArchive::KArchive ({\bf QIODevice} $\ast$ {\em dev})\hspace{0.3cm}{\tt  [protected]}}\label{classKArchive_b0}


Base constructor (protected since this is a pure virtual class). 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em 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. \end{description}
\end{Desc}


Definition at line 69 of file karchive.cpp.

\subsection{Member Function Documentation}
\index{KArchive@{KArchive}!open@{open}}
\index{open@{open}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KArchive::open (int {\em mode})\hspace{0.3cm}{\tt  [virtual]}}\label{classKArchive_a1}


Opens the archive for reading or writing. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em mode}]may be IO\_\-Read\-Only or IO\_\-Write\-Only Inherited classes might want to reimplement open\-Archive instead. \end{description}
\end{Desc}
\begin{Desc}
\item[See also:]{\bf close}{\rm (p.\,\pageref{classKArchive_a2})} \end{Desc}


Definition at line 85 of file karchive.cpp.

References close(), QIODevice::open(), and open\-Archive().\index{KArchive@{KArchive}!close@{close}}
\index{close@{close}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void KArchive::close ()\hspace{0.3cm}{\tt  [virtual]}}\label{classKArchive_a2}


Closes the archive. 

Inherited classes might want to reimplement close\-Archive instead.

\begin{Desc}
\item[See also:]{\bf open}{\rm (p.\,\pageref{classKArchive_a1})} \end{Desc}


Definition at line 105 of file karchive.cpp.

References QIODevice::close(), and close\-Archive().

Referenced by open(), KAr::$\sim$KAr(), KTar::$\sim$KTar(), and KZip::$\sim$KZip().\index{KArchive@{KArchive}!isOpened@{isOpened}}
\index{isOpened@{isOpened}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KArchive::is\-Opened () const\hspace{0.3cm}{\tt  [inline]}}\label{classKArchive_a3}


\begin{Desc}
\item[Returns:]true if the archive is opened \end{Desc}


Definition at line 70 of file karchive.h.

Referenced by KZip::prepare\-Writing(), KTar::prepare\-Writing(), KTar::set\-Orig\-File\-Name(), KTar::write\-Dir(), KAr::$\sim$KAr(), KTar::$\sim$KTar(), and KZip::$\sim$KZip().\index{KArchive@{KArchive}!mode@{mode}}
\index{mode@{mode}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int KArchive::mode () const\hspace{0.3cm}{\tt  [inline]}}\label{classKArchive_a4}


\begin{Desc}
\item[Returns:]the mode in which the archive was opened (IO\_\-Read\-Only or IO\_\-Write\-Only) \end{Desc}


Definition at line 75 of file karchive.h.

Referenced by KZip::close\-Archive(), KZip::prepare\-Writing(), KTar::prepare\-Writing(), KTar::set\-Orig\-File\-Name(), and KTar::write\-Dir().\index{KArchive@{KArchive}!device@{device}}
\index{device@{device}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf QIODevice}$\ast$ KArchive::device () const\hspace{0.3cm}{\tt  [inline]}}\label{classKArchive_a5}


The underlying device. 



Definition at line 80 of file karchive.h.

Referenced by KZip::close\-Archive(), KArchive\-File::data(), KZip::done\-Writing(), KTar::done\-Writing(), KZip::open\-Archive(), KTar::open\-Archive(), KAr::open\-Archive(), KZip::prepare\-Writing(), KTar::prepare\-Writing(), KTar::set\-Orig\-File\-Name(), KTar::write\-Dir(), KZip::write\-File(), write\-File(), KAr::$\sim$KAr(), KTar::$\sim$KTar(), and KZip::$\sim$KZip().\index{KArchive@{KArchive}!directory@{directory}}
\index{directory@{directory}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}const  {\bf KArchive\-Directory} $\ast$ KArchive::directory () const}\label{classKArchive_a6}


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.\index{KArchive@{KArchive}!writeDir@{writeDir}}
\index{writeDir@{writeDir}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KArchive::write\-Dir (const {\bf QString} \& {\em name}, const {\bf QString} \& {\em user}, const {\bf QString} \& {\em group})\hspace{0.3cm}{\tt  [pure virtual]}}\label{classKArchive_a7}


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 {\bf KAr} {\rm (p.\,\pageref{classKAr_a6})}, {\bf KTar} {\rm (p.\,\pageref{classKTar_a5})}, and {\bf KZip} {\rm (p.\,\pageref{classKZip_b2})}.\index{KArchive@{KArchive}!writeFile@{writeFile}}
\index{writeFile@{writeFile}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}bool KArchive::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{classKArchive_a8}


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. 

Reimplemented in {\bf KZip} {\rm (p.\,\pageref{classKZip_a6})}.

Definition at line 126 of file karchive.cpp.

References device(), done\-Writing(), KStd\-Accel::name(), prepare\-Writing(), and QIODevice::write\-Block().\index{KArchive@{KArchive}!prepareWriting@{prepareWriting}}
\index{prepareWriting@{prepareWriting}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KArchive::prepare\-Writing (const {\bf QString} \& {\em name}, const {\bf QString} \& {\em user}, const {\bf QString} \& {\em group}, uint {\em size})\hspace{0.3cm}{\tt  [pure virtual]}}\label{classKArchive_a9}


Here's another way of writing a file into an archive: Call {\bf prepare\-Writing}{\rm (p.\,\pageref{classKArchive_a9})}, then call {\bf device()}{\rm (p.\,\pageref{classKArchive_a5})}-$>$write\-Block() (for tar files) or write\-Data (for zip files) [NEW VIRTUAL METHOD NEEDED] as many times as wanted then call {\bf done\-Writing}{\rm (p.\,\pageref{classKArchive_a10})}( 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. 



Implemented in {\bf KAr} {\rm (p.\,\pageref{classKAr_a4})}, {\bf KTar} {\rm (p.\,\pageref{classKTar_a6})}, and {\bf KZip} {\rm (p.\,\pageref{classKZip_a7})}.

Referenced by write\-File().\index{KArchive@{KArchive}!doneWriting@{doneWriting}}
\index{doneWriting@{doneWriting}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KArchive::done\-Writing (uint {\em size})\hspace{0.3cm}{\tt  [pure virtual]}}\label{classKArchive_a10}


Call {\bf done\-Writing}{\rm (p.\,\pageref{classKArchive_a10})} after writing the data. 

\begin{Desc}
\item[See also:]{\bf prepare\-Writing}{\rm (p.\,\pageref{classKArchive_a9})} \end{Desc}


Implemented in {\bf KAr} {\rm (p.\,\pageref{classKAr_a5})}, {\bf KTar} {\rm (p.\,\pageref{classKTar_a7})}, and {\bf KZip} {\rm (p.\,\pageref{classKZip_a9})}.

Referenced by write\-File().\index{KArchive@{KArchive}!openArchive@{openArchive}}
\index{openArchive@{openArchive}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KArchive::open\-Archive (int {\em mode})\hspace{0.3cm}{\tt  [protected, pure virtual]}}\label{classKArchive_b1}


Opens an archive for reading or writing. 

Called by {\bf open}{\rm (p.\,\pageref{classKArchive_a1})}. 

Implemented in {\bf KAr} {\rm (p.\,\pageref{classKAr_b0})}, {\bf KTar} {\rm (p.\,\pageref{classKTar_b0})}, and {\bf KZip} {\rm (p.\,\pageref{classKZip_b0})}.

Referenced by open().\index{KArchive@{KArchive}!closeArchive@{closeArchive}}
\index{closeArchive@{closeArchive}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}virtual bool KArchive::close\-Archive ()\hspace{0.3cm}{\tt  [protected, pure virtual]}}\label{classKArchive_b2}


Closes the archive. 

Called by {\bf close}{\rm (p.\,\pageref{classKArchive_a2})}. 

Implemented in {\bf KAr} {\rm (p.\,\pageref{classKAr_b1})}, {\bf KTar} {\rm (p.\,\pageref{classKTar_b1})}, and {\bf KZip} {\rm (p.\,\pageref{classKZip_b1})}.

Referenced by close().\index{KArchive@{KArchive}!rootDir@{rootDir}}
\index{rootDir@{rootDir}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KArchive\-Directory} $\ast$ KArchive::root\-Dir ()\hspace{0.3cm}{\tt  [protected, virtual]}}\label{classKArchive_b3}


Retrieves or create the root directory. 

The default implementation assumes that {\bf open\-Archive()}{\rm (p.\,\pageref{classKArchive_b1})} 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::decode\-Name(), QString::from\-Latin1(), and QString::number().

Referenced by find\-Or\-Create(), KZip::open\-Archive(), KTar::open\-Archive(), KAr::open\-Archive(), and KZip::prepare\-Writing().\index{KArchive@{KArchive}!findOrCreate@{findOrCreate}}
\index{findOrCreate@{findOrCreate}!KArchive@{KArchive}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf KArchive\-Directory} $\ast$ KArchive::find\-Or\-Create (const {\bf QString} \& {\em path})\hspace{0.3cm}{\tt  [protected]}}\label{classKArchive_b4}


Ensures that {\tt 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 KArchive\-Directory::add\-Entry(), KArchive\-Directory::entry(), QString::find\-Rev(), KArchive\-Entry::is\-Directory(), QString::left(), QString::mid(), and root\-Dir().

Referenced by KZip::open\-Archive(), KTar::open\-Archive(), and KZip::prepare\-Writing().

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