Canorus 0.0
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CATar Class Reference

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

#include <tar.h>

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 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

◆ CATar() [1/2]

CATar::CATar ( )

Creates an empty tar file

◆ CATar() [2/2]

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::~CATar ( )
virtual

Destroys a tar archive

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

Member Function Documentation

◆ addFile() [1/2]

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

References addFile().

Here is the call graph for this function:

◆ addFile() [2/2]

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(), CHUNK, contains(), file(), NULL, and removeFile().

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bufncpy()

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:

◆ bufncpyi()

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:

◆ close()

void CATar::close ( QIODevice &  dest)
inline

References _pos.

Referenced by CAArchive::write().

Here is the caller graph for this function:

◆ contains()

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:

◆ eof()

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:

◆ error()

bool CATar::error ( )
inline

References _ok.

Referenced by CAArchive::error().

Here is the caller graph for this function:

◆ file()

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:

◆ numToOct()

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:

◆ numToOcti()

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:

◆ open()

bool CATar::open ( QIODevice &  dest)
inline

References _pos.

Referenced by CAArchive::write().

Here is the caller graph for this function:

◆ parse()

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, and file().

Referenced by CATar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeFile()

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:

◆ write() [1/2]

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:

◆ write() [2/2]

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, 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:

◆ writeHeader()

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

Member Data Documentation

◆ _files

QList<CATarFile*> CATar::_files
protected

◆ _ok

bool CATar::_ok
protected

Referenced by error(), and parse().

◆ _pos

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

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

◆ CHUNK

const int CATar::CHUNK = 16384
staticprotected

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


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