From 6fd28379a962585838d72e69f376d28325723974 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 11 Mar 2023 00:55:26 +0100 Subject: [PATCH] TarStream: Add a direct pointer to entry data in the Entry struct --- libluna/include/luna/TarStream.h | 8 +++++++- libluna/src/TarStream.cpp | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/libluna/include/luna/TarStream.h b/libluna/include/luna/TarStream.h index 7ee5a909..3bb00ef3 100644 --- a/libluna/include/luna/TarStream.h +++ b/libluna/include/luna/TarStream.h @@ -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; }; diff --git a/libluna/src/TarStream.cpp b/libluna/src/TarStream.cpp index f4fcae66..5b91307e 100644 --- a/libluna/src/TarStream.cpp +++ b/libluna/src/TarStream.cpp @@ -45,7 +45,8 @@ Result 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; }