Skip to content

Commit

Permalink
Add helper to copy a file between two archives
Browse files Browse the repository at this point in the history
  • Loading branch information
milasudril committed Jul 1, 2023
1 parent 64551e7 commit abf2e2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/wad64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,28 @@ void Wad64::insert(Archive& archive,
}
}

void Wad64::insert(Archive& archive,
FileCreationMode mode,
ArchiveView const& src_archive,
std::string_view src_name,
std::string_view dest_name)
{
InputFile file_in{src_archive, src_name};
OutputFile file_out{archive, dest_name, mode};

auto buffer = std::make_unique<std::array<std::byte, 0x10000>>();
auto bytes_left = static_cast<size_t>(file_in.size());
int64_t read_offset = 0;
while(bytes_left != 0)
{
auto const n = read(
file_in, std::span{buffer->data(), std::min(buffer->size(), bytes_left)}, read_offset);
write(file_out, std::span{buffer->data(), n});
bytes_left -= n;
read_offset += n;
}
}

void Wad64::insert(Archive& archive,
FileCreationMode mode,
std::span<std::byte const> data,
Expand Down
6 changes: 6 additions & 0 deletions lib/wad64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ namespace Wad64
char const* src_name,
std::string_view dest_name);

void insert(Archive& archive,
FileCreationMode mode,
ArchiveView const& src_archive,
std::string_view src_name,
std::string_view dest_name);

void insert(Archive& archive,
FileCreationMode mode,
std::span<std::byte const> data,
Expand Down

0 comments on commit abf2e2d

Please sign in to comment.