Skip to content

Commit

Permalink
Implement file import functionality and add import tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryKogan committed Dec 13, 2023
1 parent d8f5a5c commit 28dbcdf
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/FileSystem/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,16 @@ auto FileSystem::import_file(std::istream &in_stream, std::string const &path) -
auto file_writer = get_writer(path);
file_writer.set_offset(0);

auto buffer = std::vector<std::byte>(settings_.cluster_size);
while (in_stream.read(reinterpret_cast<char *>(buffer.data()), // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
static_cast<std::streamsize>(settings_.cluster_size))) {
in_stream.seekg(0);
std::istreambuf_iterator<char> iter(in_stream);
std::istreambuf_iterator<char> end;

while (iter != end) {
std::vector<std::byte> buffer;
buffer.reserve(settings_.cluster_size);
for (std::size_t i = 0; i < settings_.cluster_size && iter != end; ++iter, ++i) {
buffer.push_back(static_cast<std::byte>(*iter));
}
file_writer.write_next(buffer);
}
}
Expand Down
Loading

0 comments on commit 28dbcdf

Please sign in to comment.