FileSystem: Add read/write binary stream helpers
This commit is contained in:
parent
41be96ef93
commit
61d0af30a2
|
@ -591,6 +591,39 @@ bool WriteStreamToString(const std::string_view& sv, ByteStream* stream)
|
||||||
return stream->Write2(sv.data(), static_cast<u32>(sv.size()));
|
return stream->Write2(sv.data(), static_cast<u32>(sv.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<u8> ReadBinaryStream(ByteStream* stream, bool seek_to_start /*= true*/)
|
||||||
|
{
|
||||||
|
u64 pos = stream->GetPosition();
|
||||||
|
u64 size = stream->GetSize();
|
||||||
|
if (pos > 0 && seek_to_start)
|
||||||
|
{
|
||||||
|
if (!stream->SeekAbsolute(0))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert(size >= pos);
|
||||||
|
size -= pos;
|
||||||
|
if (size == 0 || size > std::numeric_limits<u32>::max())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
std::vector<u8> ret;
|
||||||
|
ret.resize(static_cast<size_t>(size));
|
||||||
|
if (!stream->Read2(ret.data(), static_cast<u32>(size)))
|
||||||
|
return {};
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WriteBinaryToSTream(ByteStream* stream, const void* data, size_t data_length)
|
||||||
|
{
|
||||||
|
if (data_length > std::numeric_limits<u32>::max())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return stream->Write2(data, static_cast<u32>(data_length));
|
||||||
|
}
|
||||||
|
|
||||||
void BuildOSPath(char* Destination, u32 cbDestination, const char* Path)
|
void BuildOSPath(char* Destination, u32 cbDestination, const char* Path)
|
||||||
{
|
{
|
||||||
u32 i;
|
u32 i;
|
||||||
|
|
|
@ -187,6 +187,9 @@ bool WriteFileToString(const char* filename, const std::string_view& sv);
|
||||||
std::string ReadStreamToString(ByteStream* stream, bool seek_to_start = true);
|
std::string ReadStreamToString(ByteStream* stream, bool seek_to_start = true);
|
||||||
bool WriteStreamToString(const std::string_view& sv, ByteStream* stream);
|
bool WriteStreamToString(const std::string_view& sv, ByteStream* stream);
|
||||||
|
|
||||||
|
std::vector<u8> ReadBinaryStream(ByteStream* stream, bool seek_to_start = true);
|
||||||
|
bool WriteBinaryToSTream(ByteStream* stream, const void* data, size_t data_length);
|
||||||
|
|
||||||
// creates a directory in the local filesystem
|
// creates a directory in the local filesystem
|
||||||
// if the directory already exists, the return value will be true.
|
// if the directory already exists, the return value will be true.
|
||||||
// if Recursive is specified, all parent directories will be created
|
// if Recursive is specified, all parent directories will be created
|
||||||
|
|
Loading…
Reference in New Issue