1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-16 23:34:10 +02:00

Implement FileStream SetLength

This commit is contained in:
disarray2077 2021-08-01 17:38:30 -03:00
parent 4bd3cc641d
commit 06fe5a98c6
8 changed files with 83 additions and 10 deletions

View file

@ -235,6 +235,32 @@ namespace System.IO
return .Err;
return .Ok;
}
public override Result<void> SetLength(int64 length)
{
int64 pos = Position;
if (pos != length)
Seek(length);
Platform.BfpFileResult result = .Ok;
Platform.BfpFile_Truncate(mBfpFile, &result);
if (result != .Ok)
{
Seek(pos);
return .Err;
}
if (pos != length)
{
if (pos < length)
Seek(pos);
else
Seek(0, .FromEnd);
}
return .Ok;
}
}
class BufferedFileStream : BufferedStream
@ -452,6 +478,40 @@ namespace System.IO
return .Err;
return numBytesRead;
}
public override Result<void> SetLength(int64 length)
{
Try!(Flush());
int64 pos = Position;
if (pos != length || pos != mBfpFilePos)
{
Try!(SeekUnderlying(length));
mPos = length;
}
Platform.BfpFileResult result = .Ok;
Platform.BfpFile_Truncate(mBfpFile, &result);
if (result != .Ok)
{
Try!(SeekUnderlying(pos));
return .Err;
}
mUnderlyingLength = length;
mPos = Math.Min(pos, Length);
if (pos != length)
{
if (pos < length)
Try!(SeekUnderlying(pos));
else
Try!(SeekUnderlying(0, .FromEnd));
}
return .Ok;
}
}
class FileStream : BufferedFileStream