mirror of
https://github.com/beefytech/Beef.git
synced 2025-07-04 23:36: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
|
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)
|
public override Result<void> Seek(int64 pos, SeekKind seekKind = .Absolute)
|
||||||
{
|
{
|
||||||
int64 length = Length;
|
|
||||||
|
|
||||||
int64 newPos;
|
|
||||||
switch (seekKind)
|
switch (seekKind)
|
||||||
{
|
{
|
||||||
case .Absolute:
|
case .Absolute:
|
||||||
mPos = Math.Min(pos, length);
|
mPos = pos;
|
||||||
if (pos > length)
|
|
||||||
return .Err;
|
|
||||||
case .FromEnd:
|
case .FromEnd:
|
||||||
newPos = length - pos;
|
mPos = Length + pos;
|
||||||
case .Relative:
|
case .Relative:
|
||||||
mPos = Math.Min(mPos + pos, length);
|
mPos = mPos + pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
return .Ok;
|
return .Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +172,12 @@ namespace System.IO
|
||||||
|
|
||||||
public override Result<void> Close()
|
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()
|
public this()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -416,16 +425,37 @@ namespace System.IO
|
||||||
mFileAccess = access;
|
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()
|
public override Result<void> Close()
|
||||||
{
|
{
|
||||||
var hadError = Flush() case .Err;
|
let ret = base.Close();
|
||||||
if (mBfpFile != null)
|
if (mBfpFile != null)
|
||||||
Platform.BfpFile_Release(mBfpFile);
|
Platform.BfpFile_Release(mBfpFile);
|
||||||
|
|
||||||
mBfpFile = null;
|
mBfpFile = null;
|
||||||
mFileAccess = default;
|
mFileAccess = default;
|
||||||
if (hadError)
|
mBfpFilePos = 0;
|
||||||
return .Err;
|
return ret;
|
||||||
return .Ok;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateLength()
|
protected override void UpdateLength()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue