sptk2 logo
SPTK Home Page
Tar.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/ArchiveFile.h>
30#include <sptk5/Buffer.h>
31#include <sptk5/Exception.h>
32#include <sptk5/Strings.h>
33#include <sptk5/sptk.h>
34
35namespace sptk {
36
43class SP_EXPORT Tar
44{
45 using FileCollection = std::map<String, SArchiveFile>;
46
47public:
51 Tar() = default;
52
57 explicit Tar(const Buffer& tarData);
58
63 explicit Tar(const String& tarFileName);
64
71 void read(const String& fileName)
72 {
73 read(fileName.c_str());
74 }
75
82 void read(const char* fileName);
83
90 void read(const Buffer& tarData);
91
95 [[maybe_unused]] Strings fileList() const
96 {
97 Strings fileNames;
98 for (const auto& [fileName, data]: m_files)
99 {
100 fileNames.push_back(fileName);
101 }
102 return fileNames;
103 }
104
110 const ArchiveFile& file(const String& fileName) const;
111
116 void remove(const String& filename);
117
122 void append(const SArchiveFile& file);
123
128 void save(const String& tarFileName) const;
129
133 void clear();
134
135private:
136 FileCollection m_files;
137 String m_fileName;
138
139 [[nodiscard]] bool readNextFile(const Buffer& buffer, size_t& offset);
140};
141
142} // namespace sptk
File inside tar archive.
Definition: ArchiveFile.h:69
Definition: Buffer.h:51
Definition: String.h:49
Definition: Strings.h:52
void push_back(const String &str)
Definition: Strings.h:237
Definition: Tar.h:44
Strings fileList() const
Definition: Tar.h:95
Tar()=default
const ArchiveFile & file(const String &fileName) const
void read(const Buffer &tarData)
void remove(const String &filename)
void save(const String &tarFileName) const
Tar(const String &tarFileName)
void clear()
void read(const char *fileName)
void append(const SArchiveFile &file)
void read(const String &fileName)
Definition: Tar.h:71
Tar(const Buffer &tarData)

Fri Oct 14 2022 09:58:32: SPTK 5.4.1