47 lines
1009 B
C++
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;
|
|
}
|
|
} |