|
Canorus
0.0
|
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 |
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).
| CATar::CATar | ( | ) |
Creates an empty tar file
| CATar::CATar | ( | QIODevice & | data | ) |
Parse the given tar file and allow reading from it.
References parse().

|
virtual |
Destroys a tar archive
References _files, and CATar::CATarFile::data.
| bool CATar::addFile | ( | const QString & | filename, |
| QByteArray | data, | ||
| bool | replace = true |
||
| ) |
| bool CATar::addFile | ( | const QString & | filename, |
| QIODevice & | data, | ||
| bool | replace = true |
||
| ) |
Adds a file to the tar archive.
| filename | The full name of the file (including directory path). |
| data | A reader for the file. |
| replace | Whether to replace the file, if it's already in the archive. Default is true. |
References _files, bufncpy(), CHUNK, contains(), file(), NULL, and removeFile().
Referenced by addFile(), and CAArchive::addFile().


|
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().

|
protected |
References bufncpy().
Referenced by writeHeader().


|
inline |
|
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().

| bool CATar::eof | ( | QIODevice & | dest | ) |
References _files, _pos, and CATar::CATarBufInfo::eof.
Referenced by CAArchive::write(), and write().

|
inline |
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.
| filename | The 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().

|
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().

|
protected |
References numToOct().
Referenced by writeHeader().


|
inline |
|
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().


| 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().

| qint64 CATar::write | ( | QIODevice & | dest | ) |
| 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.
| dest | The destination device. |
| chunk | max 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().


|
protected |
Converts the file header to ASCII octal format.
References _files, bufncpyi(), file(), CATar::CATarHeader::gid, CATar::CATarHeader::gname, CATar::CATarFile::hdr, CATar::CATarHeader::linkname, CATar::CATarHeader::mode, CATar::CATarHeader::mtime, CATar::CATarHeader::name, NULL, numToOct(), numToOcti(), CATar::CATarHeader::prefix, CATar::CATarHeader::size, CATar::CATarHeader::typeflag, CATar::CATarHeader::uid, and CATar::CATarHeader::uname.
Referenced by write().


|
protected |
Referenced by addFile(), contains(), eof(), file(), parse(), removeFile(), write(), writeHeader(), and ~CATar().
|
protected |