Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef TAR_H
00029 #define TAR_H
00030
00031 #include <zlib.h>
00032
00033 #include "QGpCoreToolsDLLExport.h"
00034 #include "Translations.h"
00035 #include "CoreApplication.h"
00036 #include "Trace.h"
00037
00038 namespace QGpCoreTools {
00039
00040 class TarHeader;
00041
00042 class QGPCORETOOLS_EXPORT Tar
00043 {
00044 TRANSLATIONS("Tar")
00045 public:
00046 Tar();
00047 ~Tar();
00048
00049 bool open(QString file, QIODevice::OpenMode m);
00050 void close();
00051 QString fileName() const {return _fileName;}
00052
00053 bool addFile(QString fileName, const QByteArray& data);
00054 bool nextFile(QString& fileName, QByteArray& data, bool cache=false );
00055 bool file(const QString fileName, QByteArray& data);
00056 bool rewind();
00057 private:
00058 inline bool writeBlock(const char * buffer);
00059 inline bool readBlock(char * buffer);
00060 char * int2octal(int val);
00061 int octal2int(const char * octStr);
00062 uint checksum(TarHeader& fh);
00063 bool readFile(TarHeader& fh, QByteArray& data);
00064
00065 gzFile _f;
00066 QString _fileName;
00067 QIODevice::OpenMode _mode;
00068 QCache<QString, QByteArray> _cachedFiles;
00069 QMap<QString, z_off_t> _fileOffsets;
00070 };
00071
00072 inline bool Tar::writeBlock(const char * buffer)
00073 {
00074 TRACE;
00075
00076 if(gzwrite (_f, (void *) buffer, 512)!=512) {
00077 App::stream() << tr("Cannot write block in tar file") << endl;
00078 return false;
00079 } else {
00080 return true;
00081 }
00082 }
00083
00084 inline bool Tar::readBlock(char * buffer)
00085 {
00086 TRACE;
00087 int nb=gzread (_f, buffer, 512);
00088 if(nb!=512) {
00089 App::stream() << tr("Cannot read a block of 512 bytes in tar file") << endl;
00090 return false;
00091 } else {
00092 return true;
00093 }
00094 }
00095
00096 }
00097
00098 #endif // TAR_H