TarWriter.h
1/* Copyright (C) 2008 Marc Boris Duerner
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 2.1 of the License, or (at your option) any later version.
7
8 As a special exception, you may use this file as part of a free
9 software library without restriction. Specifically, if other files
10 instantiate templates or use macros or inline functions from this
11 file, or you compile this file and link it with other files to
12 produce an executable, this file does not by itself cause the
13 resulting executable to be covered by the GNU General Public
14 License. This exception does not however invalidate any other
15 reasons why the executable file might be covered by the GNU Library
16 General Public License.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 MA 02110-1301 USA
27*/
28
29#ifndef PT_SYSTEM_TAR_WRITER_H
30#define PT_SYSTEM_TAR_WRITER_H
31
32#include <Pt/System/Path.h>
33#include <Pt/System/FileInfo.h>
34
35#include <ostream>
36#include <cstddef>
37
38namespace Pt {
39
40namespace System {
41
77class PT_SYSTEM_API TarWriter
78{
79 public:
83
86 explicit TarWriter(std::ostream& os);
87
91
94 void attach(std::ostream& os);
95
98 void detach();
99
102 void reset();
103
111 void addFile(const Pt::System::Path& path,
112 const char* data,
113 std::size_t size,
114 Pt::System::FileInfo::Perms permissions);
115
122 Pt::System::FileInfo::Perms permissions);
123
129 void addSymlink(const Pt::System::Path& path,
130 const Pt::System::Path& target);
131
138 const Pt::System::Path& target);
139
150 void beginFile(const Pt::System::Path& path,
151 std::size_t totalSize,
152 Pt::System::FileInfo::Perms permissions);
153
165 void writeFile(const char* data, std::size_t size);
166
174 void endFile();
175
178 void finish();
179
180 private:
181 TarWriter(const TarWriter&);
182
183 TarWriter& operator=(const TarWriter&);
184
185 private:
186 class TarWriterImpl* _impl;
187};
188
189
190} // namespace System
191
192} // namespace Pt
193
194#endif // include guard
Perms
File permission flags.
Definition FileInfo.h:117
Represents a path in the file-system.
Definition Path.h:48
void addSymlink(const Pt::System::Path &path, const Pt::System::Path &target)
Write a symbolic-link entry.
TarWriter()
Default constructor.
void addDirectory(const Pt::System::Path &path, Pt::System::FileInfo::Perms permissions)
Write a directory entry.
void writeFile(const char *data, std::size_t size)
Write a chunk of data for the current streaming file entry.
~TarWriter()
Destructor.
void finish()
Write the end-of-archive marker (two 512-byte null blocks).
void attach(std::ostream &os)
Attach to an output stream.
void endFile()
Finish the current streaming file entry started by beginFile().
TarWriter(std::ostream &os)
Constructor attaching to os.
void addFile(const Pt::System::Path &path, const char *data, std::size_t size, Pt::System::FileInfo::Perms permissions)
Write a regular file entry.
void detach()
Detach from the current output stream.
void reset()
Detach from the current output stream and reset state.
void addHardlink(const Pt::System::Path &path, const Pt::System::Path &target)
Write a hard-link entry.
void beginFile(const Pt::System::Path &path, std::size_t totalSize, Pt::System::FileInfo::Perms permissions)
Begin writing a regular file entry for streaming.
System programming
Definition Connection.h:26
Core module.
Definition Allocator.h:33