-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathfilesystem_extractor.h
97 lines (76 loc) · 2.6 KB
/
filesystem_extractor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* vim:set ts=2 sw=2 sts=2 et: */
/**
* \author Marcus Holland-Moritz (github@mhxnet.de)
* \copyright Copyright (c) Marcus Holland-Moritz
*
* This file is part of dwarfs.
*
* dwarfs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dwarfs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <filesystem>
#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <string_view>
namespace dwarfs {
class library_dependencies;
class logger;
class os_access;
namespace reader {
class filesystem_v2;
}
namespace utility {
struct filesystem_extractor_options {
size_t max_queued_bytes{static_cast<size_t>(512) << 20};
bool continue_on_error{false};
std::function<void(std::string_view, uint64_t, uint64_t)> progress;
};
class filesystem_extractor {
public:
filesystem_extractor(logger& lgr, os_access const& os);
static void add_library_dependencies(library_dependencies& deps);
void
open_archive(std::filesystem::path const& output, std::string const& format) {
return impl_->open_archive(output, format);
}
void open_stream(std::ostream& os, std::string const& format) {
return impl_->open_stream(os, format);
}
void open_disk(std::filesystem::path const& output) {
return impl_->open_disk(output);
}
void close() { return impl_->close(); }
bool extract(reader::filesystem_v2 const& fs,
filesystem_extractor_options const& opts =
filesystem_extractor_options()) {
return impl_->extract(fs, opts);
}
class impl {
public:
virtual ~impl() = default;
virtual void open_archive(std::filesystem::path const& output,
std::string const& format) = 0;
virtual void open_stream(std::ostream& os, std::string const& format) = 0;
virtual void open_disk(std::filesystem::path const& output) = 0;
virtual void close() = 0;
virtual bool extract(reader::filesystem_v2 const& fs,
filesystem_extractor_options const& opts) = 0;
};
private:
std::unique_ptr<impl> impl_;
};
} // namespace utility
} // namespace dwarfs