Qt TAR classes
Table Of Contents
- class QtTAR
- class QtTarBall
- enumeration HiddenFileTypes
- structure HiddenFileInfo
class QtTAR
Functionality
Handling TAR header packet.
Declaration
class QtTAR
{
public:
explicit QtTAR (void) ;
virtual ~QtTAR (void) ;
virtual int BlockSize (void) const ;
virtual bool isBlock (QByteArray & block) ;
virtual bool isPadding (QByteArray & block) ;
virtual qint64 FileBlocks (qint64 size) ;
virtual int Checksum (QByteArray & block,char replace = ' ') ;
virtual bool Extract (QByteArray & block ,void * hiddenFileInfo) ; // block => File
virtual bool Bale (void * hiddenFileInfo,QByteArray & data ) ; // File <= Data
protected:
QString toOct (int checksum) ;
void PackOct (char * buf,qint64 size,int length) ;
qint64 FromOct (char * buf,int length) ;
private:
void Copy (char * buf,QString string) ;
} ;
Explanation
int BlockSize(void) const
TAR header size, normally 512 bytes.
bool isBlock(QByteArray & block)
Check if block is a TAR header packet.
bool isPadding(QByteArray & block)
Check if block is a padding header packet.
qint64 FileBlocks(qint64 size)
Convert size into 512 bytes alignement.
int Checksum(QByteArray & block,char replace = ' ')
Checksum for TAR header packet.
bool Extract(QByteArray & block,void * hiddenFileInfo)
Convert TAR header packet into HiddenFileInfo.
bool Bale(void * hiddenFileInfo,QByteArray & data)
Convert HiddenFileInfo into TAR header packet.
QString toOct(int checksum)
Convert Checksum value into oct-string.
void PackOct(char * buf,qint64 size,int length)
Convert size into oct-string and copy into buf.
qint64 FromOct(char * buf,int length)
Convert buf into qint64 in oct-format.
void Copy(char * buf,QString string)
Copy string into buf.
class QtTarBall
Functionality
Handling TarBall contents. To handle a TAR file, normally you
need to inherit this class.
Decalaration
class QtTarBall : public QtTAR
{
public:
explicit QtTarBall (void) ;
virtual ~QtTarBall (void) ;
virtual bool List (QDir root,QIODevice & IO) ;
virtual bool List (QDir root,QString filename) ;
virtual bool Extract (QDir root,QIODevice & IO) ;
virtual bool Extract (QDir root,QString filename) ;
virtual bool TarBall (QIODevice & IO,QDir root,QDir source,bool recursive = true) ;
virtual bool TarBall (QString filename,QDir root,QDir source,bool recursive = true) ;
protected:
virtual bool Interval (void) ;
virtual void Report (void * hiddenFileInfo) ;
virtual bool ListFile (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool Extract (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool Read (QIODevice & IO,QByteArray & data,qint64 size) ;
virtual bool Skip (QIODevice & IO,qint64 size) ;
virtual bool Write (QIODevice & IO,QByteArray & data) ;
virtual bool WriteClose (QIODevice & IO) ;
virtual bool WriteFile (QIODevice & IO,QFileInfo & file) ;
virtual bool ExtractFile (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool ExtractDir (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool ExtractLink (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool ExtractDEVs (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool ExtractNext (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool ExtractEXT (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool setFileTime (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual bool setFileMode (QDir root,QIODevice & IO,void * hiddenFileInfo) ;
virtual QFileInfoList Listing (QDir & root,QDir source) ;
virtual bool WriteTAR (QIODevice & IO,QDir & root,QFileInfo & file) ;
virtual bool ToHiddenFileInfo (QDir & root,QFileInfo & file,void * hiddenFileInfo) ;
virtual void * NewHiddenFile (void) ;
virtual void CleanHiddenFile (void * hiddenFileInfo) ;
private:
} ;
Explanation
bool List(QDir root,QIODevice & IO)
Listing files inside the TAR file by IO.
bool List(QDir root,QString filename)
Listing files inside the TAR file by filename.
bool Extract(QDir root,QIODevice & IO)
Extract a TAR file by IO.
bool Extract(QDir root,QString filename)
Extract a TAR file by filename.
bool TarBall(QIODevice & IO,QDir root,QDir source,bool recursive = true)
Create a TAR file by IO by collecting all files inside directory
source.
bool TarBall(QString filename,QDir root,QDir source,bool recursive = true)
Create a TAR file by filename by collecting all files inside
directory source.
bool Interval(void)
Most long process in QtTarBall, Interval() will be called to prevent
lock-up. If you want to add an interval process for your own,
you should inherit this function. Normally, in a Qt program, this
function should call qApp->processEvents() to prevent GUI
lock-up.
void Report(void * hiddenFileInfo)
Report HiddenFileInfo.This function is only called by ListFile,
default do nothing at all. You will need to inherit this
function to report the file details.
bool ListFile(QDir root,QIODevice & IO,void * hiddenFileInfo)
Extract HiddenFileInfo from IO file, and Call function Report to
list details information about HiddentFileInfo.
bool Extract(QDir root,QIODevice & IO,void * hiddenFileInfo)
Extract HiddenFileInfo from IO file, and handling the files by
types.
bool Read(QIODevice & IO,QByteArray & data,qint64 size)
Read size bytes of data from IO file. IO normally is a TAR
file.
bool Skip(QIODevice & IO,qint64 size)
Equal to IO . seek ( IO.pos() + size )
This is normally used when listing a TAR file to skip the file size.
bool Write(QIODevice & IO,QByteArray & data)
Write data into IO. Normally it is a TAR file.
bool WriteClose(QIODevice & IO)
Close file IO. Normally it is a TAR file.
bool WriteFile(QIODevice & IO,QFileInfo & file)
Write file into IO. Normally this means reading file in hard
drive and write into a TAR file.
bool ExtractFile(QDir root,QIODevice & IO,void * hiddenFileInfo)
Create and handle normal file.
bool ExtractDir(QDir root,QIODevice & IO,void * hiddenFileInfo)
Create and handle directory.
bool ExtractLink(QDir root,QIODevice & IO,void * hiddenFileInfo)
Create and handle symbolic linked file.
bool ExtractDEVs(QDir root,QIODevice & IO,void * hiddenFileInfo)
Handling device node or file.
bool ExtractNext(QDir root,QIODevice & IO,void * hiddenFileInfo)
Handling S-TAR In packet
bool ExtractEXT(QDir root,QIODevice & IO,void * hiddenFileInfo)
Handling S-TAR Extended packet.
bool setFileTime(QDir root,QIODevice & IO,void * hiddenFileInfo)
Set up file creation date time and lastest modification date time.
bool setFileMode(QDir root,QIODevice & IO,void * hiddenFileInfo)
Set up file permissions.
QFileInfoList Listing(QDir & root,QDir source)
Scan all files in source directory.
bool WriteTAR(QIODevice & IO,QDir & root,QFileInfo & file)
Write normal file into TAR.
bool ToHiddenFileInfo(QDir & root,QFileInfo & file,void * hiddenFileInfo)
Convert QFileInfo into HiddenFileInfo.
void * NewHiddenFile(void)
Allocate HiddenFileInfo. User need to inherit this function to
allocate your own HiddenFileInfo define by yourself.
void CleanHiddenFile(void * hiddenFileInfo)
clear and delete hiddenFileInfo memory.
enumeration
HiddenFileTypes
HiddenFileTypes is the file type enumeration.
You must define ENABLE_HIDDEN_FILE_INFO_STRUCTURE to use this hidden
structure. Normally, it is not recommented. The
recommented method is you define your own structure and enumeration
like this one.
Name
|
Value
|
Meaning
|
None
|
0
|
Nothing
|
Regular
|
1
|
Normal file
|
Link
|
2
|
Symbolic link file
|
Symbol
|
3
|
Symbol device
|
Char
|
4
|
Char device
|
Block
|
5
|
Block device
|
Directory
|
6
|
Directory
|
FIFO
|
7
|
FIFO device
|
Reserved
|
8
|
Reserved for future usage
|
Next
|
9
|
S-TAR in
|
Extended
|
10
|
S-TAR Extended |
structure
HiddenFileInfo
HiddenFileInfo is file detail information recorder.
You must define ENABLE_HIDDEN_FILE_INFO_STRUCTURE to use this hidden
structure. Normally, it is not recommented. The
recommented method is you define your own structure and enumeration
like this one.
typedef struct HiddenFileInfo {
bool Archive ; /* inside a Tar file or Zip file, and so on */
QString Root ; /* Root directory or tarball name */
QString Filename ; /* Filename or directory name of this entry */
QString System ; /* Normally, this is operation system */
qint64 mode ; /* Unix only */
qint64 uid ; /* Unix only */
qint64 gid ; /* Unix only */
qint64 size ; /* File size, for directory, it is 0 */
QDateTime Time ; /* Creation time */
QDateTime Lastest ; /* Last modified */
QString CheckSum ; /* CheckSum of this file */
HiddenFileTypes Type ; /* File Type */
QString LinkName ; /* Unix only */
QString uname ; /* Unix only */
QString gname ; /* Unix only */
qint64 Major ; /* Unix only */
qint64 Minor ; /* Unix only */
QString Prefix ; /* Normally, this is prefix directory */
QString Comment ; /* This is from GZIP format, however, sometimes it is useful */
} HiddenFileInfo ;
Neutrino
International Inc. 2001~2015