mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibArchive: Move loading the next tar header into a helper function
This now also validates the first header that is loaded, so we can drop the corresponding FIXME from `tar`.
This commit is contained in:
parent
cbeaba0c12
commit
fd3a823a20
4 changed files with 9 additions and 16 deletions
|
@ -56,13 +56,7 @@ ErrorOr<NonnullOwnPtr<TarInputStream>> TarInputStream::construct(NonnullOwnPtr<C
|
|||
{
|
||||
auto tar_stream = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TarInputStream(move(stream))));
|
||||
|
||||
// Try and read the header.
|
||||
auto header_span = TRY(tar_stream->m_stream->read(Bytes(&tar_stream->m_header, sizeof(m_header))));
|
||||
if (header_span.size() != sizeof(m_header))
|
||||
return Error::from_string_literal("Failed to read the entire header");
|
||||
|
||||
// Discard the rest of the block.
|
||||
TRY(tar_stream->m_stream->discard(block_size - sizeof(TarFileHeader)));
|
||||
TRY(tar_stream->load_next_header());
|
||||
|
||||
return tar_stream;
|
||||
}
|
||||
|
@ -89,7 +83,13 @@ ErrorOr<void> TarInputStream::advance()
|
|||
TRY(m_stream->discard(block_ceiling(file_size) - m_file_offset));
|
||||
m_file_offset = 0;
|
||||
|
||||
// FIXME: This is not unlike the initial initialization. Maybe we should merge those two.
|
||||
TRY(load_next_header());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> TarInputStream::load_next_header()
|
||||
{
|
||||
auto header_span = TRY(m_stream->read(Bytes(&m_header, sizeof(m_header))));
|
||||
if (header_span.size() != sizeof(m_header))
|
||||
return Error::from_string_literal("Failed to read the entire header");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue