1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 2000-2005 David Faure <faure@kde.org> |
3 | Copyright (C) 2003 Leo Savernik <l.savernik@aon.at> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License version 2 as published by the Free Software Foundation. |
8 | |
9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | Boston, MA 02110-1301, USA. |
18 | */ |
19 | #ifndef KTAR_H |
20 | #define KTAR_H |
21 | |
22 | #include <karchive.h> |
23 | |
24 | /** |
25 | * A class for reading / writing (optionally compressed) tar archives. |
26 | * |
27 | * KTar allows you to read and write tar archives, including those |
28 | * that are compressed using gzip, bzip2 or xz. |
29 | * |
30 | * @author Torben Weis <weis@kde.org>, David Faure <faure@kde.org> |
31 | */ |
32 | class KDECORE_EXPORT KTar : public KArchive |
33 | { |
34 | public: |
35 | /** |
36 | * Creates an instance that operates on the given filename |
37 | * using the compression filter associated to given mimetype. |
38 | * |
39 | * @param filename is a local path (e.g. "/home/weis/myfile.tgz") |
40 | * @param mimetype "application/x-gzip", "application/x-bzip" or |
41 | * "application/x-xz" |
42 | * Do not use application/x-compressed-tar or similar - you only need to |
43 | * specify the compression layer ! If the mimetype is omitted, it |
44 | * will be determined from the filename. |
45 | */ |
46 | explicit KTar( const QString& filename, |
47 | const QString& mimetype = QString() ); |
48 | |
49 | /** |
50 | * Creates an instance that operates on the given device. |
51 | * The device can be compressed (KFilterDev) or not (QFile, etc.). |
52 | * @warning Do not assume that giving a QFile here will decompress the file, |
53 | * in case it's compressed! |
54 | * @param dev the device to read from. If the source is compressed, the |
55 | * QIODevice must take care of decompression |
56 | */ |
57 | explicit KTar( QIODevice * dev ); |
58 | |
59 | /** |
60 | * If the tar ball is still opened, then it will be |
61 | * closed automatically by the destructor. |
62 | */ |
63 | virtual ~KTar(); |
64 | |
65 | /** |
66 | * Special function for setting the "original file name" in the gzip header, |
67 | * when writing a tar.gz file. It appears when using in the "file" command, |
68 | * for instance. Should only be called if the underlying device is a KFilterDev! |
69 | * @param fileName the original file name |
70 | */ |
71 | void setOrigFileName( const QByteArray & fileName ); |
72 | |
73 | protected: |
74 | |
75 | /// Reimplemented from KArchive |
76 | virtual bool doWriteSymLink(const QString &name, const QString &target, |
77 | const QString &user, const QString &group, |
78 | mode_t perm, time_t atime, time_t mtime, time_t ctime); |
79 | /// Reimplemented from KArchive |
80 | virtual bool doWriteDir( const QString& name, const QString& user, const QString& group, |
81 | mode_t perm, time_t atime, time_t mtime, time_t ctime ); |
82 | /// Reimplemented from KArchive |
83 | virtual bool doPrepareWriting( const QString& name, const QString& user, |
84 | const QString& group, qint64 size, mode_t perm, |
85 | time_t atime, time_t mtime, time_t ctime ); |
86 | /// Reimplemented from KArchive |
87 | virtual bool doFinishWriting( qint64 size ); |
88 | |
89 | /** |
90 | * Opens the archive for reading. |
91 | * Parses the directory listing of the archive |
92 | * and creates the KArchiveDirectory/KArchiveFile entries. |
93 | * @param mode the mode of the file |
94 | */ |
95 | virtual bool openArchive( QIODevice::OpenMode mode ); |
96 | virtual bool closeArchive(); |
97 | |
98 | virtual bool createDevice( QIODevice::OpenMode mode ); |
99 | |
100 | private: |
101 | |
102 | protected: |
103 | virtual void virtual_hook( int id, void* data ); |
104 | private: |
105 | class KTarPrivate; |
106 | KTarPrivate* const d; |
107 | }; |
108 | |
109 | #endif |
110 | |