-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "base.hpp" | ||
|
||
NAMESPACE_SOUP | ||
{ | ||
struct TarIndexedFile | ||
{ | ||
char name[101]; | ||
size_t offset; | ||
size_t size; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "TarReader.hpp" | ||
|
||
#include "string.hpp" | ||
|
||
NAMESPACE_SOUP | ||
{ | ||
std::vector<TarIndexedFile> TarReader::getFileList() const SOUP_EXCAL | ||
{ | ||
r.seekEnd(); | ||
const size_t tarsize = r.getPosition(); | ||
SOUP_IF_UNLIKELY ((tarsize % 512) != 0) | ||
{ | ||
return {}; // Not a valid tarball | ||
} | ||
|
||
std::vector<TarIndexedFile> res{}; | ||
for (size_t i = 0; i != tarsize; ) | ||
{ | ||
r.seek(i + 124); | ||
char size_octal[13]; | ||
memset(size_octal, 0, sizeof(size_octal)); | ||
r.raw(size_octal, 12); | ||
size_t size; | ||
SOUP_IF_UNLIKELY (!string::toIntEx<size_t, 8>(size_octal, string::TI_FULL).consume(size)) | ||
{ | ||
break; // Tarball might end on a null block | ||
} | ||
|
||
r.seek(i + 156); | ||
char type; | ||
r.c(type); | ||
if (type == '\0' || type == '0') // Regular file? | ||
{ | ||
auto& file = res.emplace_back(); | ||
|
||
memset(file.name, 0, sizeof(file.name)); | ||
r.seek(i); | ||
r.raw(file.name, 100); | ||
|
||
file.offset = i + 512; | ||
file.size = size; | ||
} | ||
|
||
i += ((1 + ((size + 511) / 512)) * 512); | ||
} | ||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "Reader.hpp" | ||
#include "TarIndexedFile.hpp" | ||
|
||
NAMESPACE_SOUP | ||
{ | ||
struct TarReader | ||
{ | ||
Reader& r; | ||
|
||
TarReader(Reader& r) noexcept | ||
: r(r) | ||
{ | ||
} | ||
|
||
[[nodiscard]] std::vector<TarIndexedFile> getFileList() const SOUP_EXCAL; | ||
|
||
[[nodiscard]] std::string getFileContents(const TarIndexedFile& file) const SOUP_EXCAL | ||
{ | ||
r.seek(file.offset); | ||
std::string res(file.size, '\0'); | ||
r.raw(res.data(), file.size); | ||
return res; | ||
} | ||
}; | ||
} |