AuroraRuntime/Include/Aurora/IO/IStreamReader.inl
Reece 77c74f886b [*] Update IStreamReader/Writer interfaces to be backed by an Aurora Interface
[+] Aurora::IO::WriteAll
[*] Improve legacy compression API (pt 2)
2022-05-28 12:18:00 +01:00

47 lines
1009 B
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IStreamReader.inl
Date: 2022-2-1
Author: Reece
***/
#pragma once
namespace Aurora::IO
{
inline EStreamError ReadAll(IStreamReader *that, Memory::ByteBuffer &buffer)
{
static const int kBufferSize = 2048;
AuUInt len;
EStreamError ret;
AuUInt8 temp[kBufferSize];
len = kBufferSize;
ret = EStreamError::eErrorEndOfStream;
buffer = Memory::NewResizableBuffer();
while ((ret = that->Read(Memory::MemoryViewStreamWrite(temp, len))) == EStreamError::eErrorNone)
{
if (len == 0)
{
break;
}
buffer.Write(temp, len);
if (len != kBufferSize)
{
break;
}
}
if (ret == EStreamError::eErrorEndOfStream)
{
return EStreamError::eErrorNone;
}
return ret;
}
}