TarStream: Add a variant of read_contents() returning an OwnedStringView
This commit is contained in:
parent
9eb829f3a2
commit
31ee901e01
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <luna/OwnedStringView.h>
|
||||
#include <luna/Result.h>
|
||||
#include <luna/Types.h>
|
||||
|
||||
@ -33,6 +34,8 @@ class TarStream
|
||||
|
||||
usize read_contents(const Entry& entry, char* buf, usize offset, usize length);
|
||||
|
||||
Result<OwnedStringView> read_contents_as_string(const Entry& entry, usize offset, usize max);
|
||||
|
||||
private:
|
||||
struct [[gnu::packed]] TarHeader
|
||||
{
|
||||
|
@ -1,5 +1,6 @@
|
||||
#define _LUNA_SYSTEM_ERROR_EXTENSIONS
|
||||
#include <luna/Alignment.h>
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/CString.h>
|
||||
#include <luna/NumberParsing.h>
|
||||
#include <luna/TarStream.h>
|
||||
@ -95,3 +96,14 @@ usize TarStream::read_contents(const Entry& entry, char* buf, usize offset, usiz
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
Result<OwnedStringView> TarStream::read_contents_as_string(const Entry& entry, usize offset, usize max)
|
||||
{
|
||||
char* buf = TRY(make_array<char>(max + 1));
|
||||
|
||||
usize nread = read_contents(entry, buf, offset, max);
|
||||
|
||||
buf[nread] = 0;
|
||||
|
||||
return OwnedStringView{buf};
|
||||
}
|
Loading…
Reference in New Issue
Block a user