mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-21 17:28:00 +02:00
Moving corlib files out of "System" directory into root
This commit is contained in:
parent
4cd58262e4
commit
7dbfd15292
179 changed files with 3 additions and 0 deletions
79
BeefLibs/corlib/src/IO/MemoryStream.bf
Normal file
79
BeefLibs/corlib/src/IO/MemoryStream.bf
Normal file
|
@ -0,0 +1,79 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace System.IO
|
||||
{
|
||||
class MemoryStream : Stream
|
||||
{
|
||||
List<uint8> mMemory = new List<uint8>() ~ delete _;
|
||||
int mPosition = 0;
|
||||
|
||||
public override int64 Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return mPosition;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
mPosition = (.)value;
|
||||
}
|
||||
}
|
||||
|
||||
public override int64 Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return mMemory.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override Result<int> TryRead(Span<uint8> data)
|
||||
{
|
||||
let count = data.Length;
|
||||
if (count == 0)
|
||||
return .Ok(0);
|
||||
int readBytes = Math.Min(count, mMemory.Count - mPosition);
|
||||
if (readBytes <= 0)
|
||||
return .Ok(readBytes);
|
||||
|
||||
Internal.MemCpy(data.Ptr, &mMemory[mPosition], readBytes);
|
||||
mPosition += readBytes;
|
||||
return .Ok(readBytes);
|
||||
}
|
||||
|
||||
public override Result<int> TryWrite(Span<uint8> data)
|
||||
{
|
||||
let count = data.Length;
|
||||
if (count == 0)
|
||||
return .Ok(0);
|
||||
int growSize = mPosition + count - mMemory.Count;
|
||||
if (growSize > 0)
|
||||
mMemory.GrowUnitialized(growSize);
|
||||
Internal.MemCpy(&mMemory[mPosition], data.Ptr, count);
|
||||
mPosition += count;
|
||||
return .Ok(count);
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue