Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
CATar Class Reference

Class for the manipulation of tar files. More...

#include <tar.h>

List of all members.

Classes

struct  CATarBufInfo
struct  CATarFile
struct  CATarHeader

Public Member Functions

 CATar ()
 CATar (QIODevice &)
virtual ~CATar ()
bool addFile (const QString &filename, QIODevice &data, bool replace=true)
bool addFile (const QString &filename, QByteArray data, bool replace=true)
void removeFile (const QString &filename)
bool contains (const QString &filename)
CAIOPtr file (const QString &filename)
qint64 write (QIODevice &dest, qint64 chunk)
qint64 write (QIODevice &dest)
bool open (QIODevice &dest)
void close (QIODevice &dest)
bool eof (QIODevice &dest)
bool error ()

Protected Member Functions

void parse (QIODevice &data)
char * bufncpy (char *, const char *, size_t, int=-1)
char * bufncpyi (char *&, const char *, size_t, int=-1)
char * numToOct (char *, qint64, int)
char * numToOcti (char *&, qint64, int)
void writeHeader (QIODevice &dest, int file)

Protected Attributes

QList< CATarFile * > _files
bool _ok
QHash< QIODevice *, CATarBufInfo_pos

Static Protected Attributes

static const int CHUNK = 16384

Detailed Description

Class for the manipulation of tar files.

Copyright (c) 2007, Itay Perl, Canorus development team All Rights Reserved. See AUTHORS for a complete list of authors.

Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE.GPL for details.

    This class can create and read tar archives, which allow concatenation of multiple files (with directory structure) into a single file.

    The archive must be opened using \a open() before writing, and closed with close() when writing is done. Don't forget to close() the archive when you're done!

    For more info on the Tar format see <http://en.wikipedia.org/wiki/Tar_(file_format)>.

Constructor & Destructor Documentation

Creates an empty tar file

CATar::CATar ( QIODevice &  data)

Parse the given tar file and allow reading from it.

References parse().

Here is the call graph for this function:

CATar::~CATar ( ) [virtual]

Destroys a tar archive

References _files, and CATar::CATarFile::data.


Member Function Documentation

bool CATar::addFile ( const QString &  filename,
QIODevice &  data,
bool  replace = true 
)

Adds a file to the tar archive.

Parameters:
filenameThe full name of the file (including directory path).
dataA reader for the file.
replaceWhether to replace the file, if it's already in the archive. Default is true.
Returns:
True if the file has been added, false otherwise (e.g., file with the same name exists).

References _files, bufncpy(), CATar::CATarHeader::chksum, CHUNK, contains(), CATar::CATarFile::data, file(), CATar::CATarHeader::gid, CATar::CATarHeader::gname, CATar::CATarFile::hdr, CATar::CATarHeader::linkname, CATar::CATarHeader::mode, CATar::CATarHeader::mtime, CATar::CATarHeader::name, CATar::CATarHeader::prefix, removeFile(), CATar::CATarHeader::size, CATar::CATarHeader::typeflag, CATar::CATarHeader::uid, and CATar::CATarHeader::uname.

Referenced by CAArchive::addFile(), and addFile().

Here is the call graph for this function:

Here is the caller graph for this function:

bool CATar::addFile ( const QString &  filename,
QByteArray  data,
bool  replace = true 
)

References addFile().

Here is the call graph for this function:

char * CATar::bufncpy ( char *  dest,
const char *  src,
size_t  len,
int  bufsize = -1 
) [protected]

Write the first len bytes in src to dest and fill dest with ASCII NULs up to bufsize.

Similar strncpy but without enforcing null termination.

If bufsize is -1 (the default), no NULs are added.

Referenced by addFile(), bufncpyi(), and parse().

Here is the caller graph for this function:

char * CATar::bufncpyi ( char *&  dest,
const char *  src,
size_t  len,
int  bufsize = -1 
) [protected]

References bufncpy().

Referenced by writeHeader().

Here is the call graph for this function:

Here is the caller graph for this function:

void CATar::close ( QIODevice &  dest) [inline]

References _pos.

Referenced by CAArchive::write(), and write().

Here is the caller graph for this function:

bool CATar::contains ( const QString &  filename) [inline]

Returns true if the tar contains a file with the given filename. Otherwise false filename may be a relative path.

References _files, CATar::CATarFile::hdr, and CATar::CATarHeader::name.

Referenced by addFile().

Here is the caller graph for this function:

bool CATar::eof ( QIODevice &  dest)

References _files, _pos, and CATar::CATarBufInfo::eof.

Referenced by CAArchive::write(), and write().

Here is the caller graph for this function:

bool CATar::error ( ) [inline]

References _ok.

Referenced by CAArchive::error().

Here is the caller graph for this function:

CAIOPtr CATar::file ( const QString &  filename)

Returns a reader for a file in the tar. If the file is not found, an empty buffer is returned. The function returns a smart (auto) pointer to a QIODevice.

Parameters:
filenameThe file name (including its path if needed).

References _files, CATar::CATarFile::data, CATar::CATarFile::hdr, and CATar::CATarHeader::name.

Referenced by addFile(), CAArchive::file(), parse(), and writeHeader().

Here is the caller graph for this function:

char * CATar::numToOct ( char *  ,
qint64  ,
int   
) [protected]

Write num to buf in octal, with length width. Similar to snprintf but wihtout enforcing null termination. Null is inserted if it fits.

Referenced by numToOcti(), and writeHeader().

Here is the caller graph for this function:

char * CATar::numToOcti ( char *&  ,
qint64  ,
int   
) [protected]

References numToOct().

Referenced by writeHeader().

Here is the call graph for this function:

Here is the caller graph for this function:

bool CATar::open ( QIODevice &  dest) [inline]

References _pos.

Referenced by CAArchive::write().

Here is the caller graph for this function:

void CATar::parse ( QIODevice &  tar) [protected]

Parses an existing tar file and initializes this object to represent it.

Parsing stops when a parsing errors occurs. The files that were parsed until the error will be available. error() can tell whether an error ocurred.

References _files, _ok, bufncpy(), CHUNK, CATar::CATarFile::data, file(), CATar::CATarHeader::gid, CATar::CATarHeader::gname, CATar::CATarFile::hdr, CATar::CATarHeader::linkname, CATar::CATarHeader::mode, CATar::CATarHeader::mtime, CATar::CATarHeader::name, CATar::CATarHeader::prefix, CATar::CATarHeader::size, CATar::CATarHeader::typeflag, CATar::CATarHeader::uid, and CATar::CATarHeader::uname.

Referenced by CATar().

Here is the call graph for this function:

Here is the caller graph for this function:

void CATar::removeFile ( const QString &  filename)

Remove a file from the archive

References _files, CATar::CATarFile::hdr, and CATar::CATarHeader::name.

Referenced by addFile(), and CAArchive::removeFile().

Here is the caller graph for this function:

qint64 CATar::write ( QIODevice &  dest,
qint64  chunk 
)

Writes the tar file into the given device in chunks. Returns the number of chars written, or -1 if an error occurred.

Warning:
You must use the same QIODevice to get the next chunk.
Parameters:
destThe destination device.
chunkmax size to write (call again for more). Must be >= 512.

References _files, _pos, close(), CATar::CATarBufInfo::close, CATar::CATarFile::data, CATar::CATarBufInfo::eof, CATar::CATarBufInfo::file, CATar::CATarBufInfo::pos, and writeHeader().

Referenced by CAArchive::write(), and write().

Here is the call graph for this function:

Here is the caller graph for this function:

qint64 CATar::write ( QIODevice &  dest)

Write the tar file into the given device in one call. Returns the number of chars written or -1 if an error ocurred.

References CHUNK, eof(), and write().

Here is the call graph for this function:

void CATar::writeHeader ( QIODevice &  dest,
int  file 
) [protected]

Member Data Documentation

QList<CATarFile*> CATar::_files [protected]
bool CATar::_ok [protected]

Referenced by error(), and parse().

QHash<QIODevice*, CATarBufInfo> CATar::_pos [protected]

Referenced by close(), eof(), open(), and write().

const int CATar::CHUNK = 16384 [static, protected]

Referenced by addFile(), parse(), and write().


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