mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 15:26:00 +02:00
Merge pull request #996 from EinScott/bufstream-fixes
more buffered stream stuff
This commit is contained in:
commit
7b58863563
2 changed files with 45 additions and 14 deletions
|
@ -19,7 +19,7 @@ namespace System.IO
|
|||
|
||||
set
|
||||
{
|
||||
mPos = Math.Min(value, Length);
|
||||
mPos = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,20 +43,16 @@ namespace System.IO
|
|||
|
||||
public override Result<void> Seek(int64 pos, SeekKind seekKind = .Absolute)
|
||||
{
|
||||
int64 length = Length;
|
||||
|
||||
int64 newPos;
|
||||
switch (seekKind)
|
||||
{
|
||||
case .Absolute:
|
||||
mPos = Math.Min(pos, length);
|
||||
if (pos > length)
|
||||
return .Err;
|
||||
mPos = pos;
|
||||
case .FromEnd:
|
||||
newPos = length - pos;
|
||||
mPos = Length + pos;
|
||||
case .Relative:
|
||||
mPos = Math.Min(mPos + pos, length);
|
||||
mPos = mPos + pos;
|
||||
}
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
|
@ -176,7 +172,12 @@ namespace System.IO
|
|||
|
||||
public override Result<void> Close()
|
||||
{
|
||||
return Flush();
|
||||
let ret = Flush();
|
||||
|
||||
mPos = 0;
|
||||
mBufferPos = -Int32.MinValue;
|
||||
mBufferEnd = -Int32.MinValue;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -296,6 +296,15 @@ namespace System.IO
|
|||
}
|
||||
}
|
||||
|
||||
public override int64 Position
|
||||
{
|
||||
set
|
||||
{
|
||||
// Matches the behavior of Platform.BfpFile_Seek(mBfpFile, value, .Absolute);
|
||||
mPos = Math.Max(value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public this()
|
||||
{
|
||||
|
||||
|
@ -416,16 +425,37 @@ namespace System.IO
|
|||
mFileAccess = access;
|
||||
}
|
||||
|
||||
public override Result<void> Seek(int64 pos, SeekKind seekKind = .Absolute)
|
||||
{
|
||||
int64 newPos;
|
||||
switch (seekKind)
|
||||
{
|
||||
case .Absolute:
|
||||
newPos = pos;
|
||||
case .FromEnd:
|
||||
newPos = Length + pos;
|
||||
case .Relative:
|
||||
newPos = mPos + pos;
|
||||
}
|
||||
|
||||
// Matches the behaviour of Platform.BfpFile_Seek(mBfpFile, value, .Absolute);
|
||||
mPos = Math.Max(newPos, 0);
|
||||
if (seekKind == .Absolute && newPos < 0)
|
||||
return .Err;
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public override Result<void> Close()
|
||||
{
|
||||
var hadError = Flush() case .Err;
|
||||
let ret = base.Close();
|
||||
if (mBfpFile != null)
|
||||
Platform.BfpFile_Release(mBfpFile);
|
||||
|
||||
mBfpFile = null;
|
||||
mFileAccess = default;
|
||||
if (hadError)
|
||||
return .Err;
|
||||
return .Ok;
|
||||
mBfpFilePos = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected override void UpdateLength()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue