TarStream: Add a direct pointer to entry data in the Entry struct

This commit is contained in:
apio 2023-03-11 00:55:26 +01:00
parent e5a41d2d52
commit 6fd28379a9
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 10 additions and 3 deletions

View File

@ -20,8 +20,14 @@ class TarStream
mode_t mode;
EntryType type;
const u8* data() const
{
return m_data;
}
private:
usize pos;
usize m_pos;
u8* m_data;
friend class TarStream;
};

View File

@ -45,7 +45,8 @@ Result<TarStream::Entry> TarStream::parse_header(const TarStream::TarHeader* hdr
entry.mode = (mode_t)parse_unsigned_integer(hdr->mode, nullptr, 8);
entry.pos = m_offset;
entry.m_pos = m_offset;
entry.m_data = (u8*)(m_base + m_offset);
switch (hdr->typeflag)
{
@ -99,7 +100,7 @@ usize TarStream::read_contents(const Entry& entry, void* buf, usize offset, usiz
if (offset >= entry.size) return 0;
if ((length + offset) > entry.size) length = entry.size - offset;
memcpy(buf, offset_ptr(m_base, entry.pos + offset), length);
memcpy(buf, offset_ptr(m_base, entry.m_pos + offset), length);
return length;
}