diff --git a/BeefLibs/corlib/src/IO/BufferedStream.bf b/BeefLibs/corlib/src/IO/BufferedStream.bf index 08bde0ac..be432b08 100644 --- a/BeefLibs/corlib/src/IO/BufferedStream.bf +++ b/BeefLibs/corlib/src/IO/BufferedStream.bf @@ -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 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 Close() { - return Flush(); + let ret = Flush(); + + mPos = 0; + mBufferPos = -Int32.MinValue; + mBufferEnd = -Int32.MinValue; + return ret; } } } diff --git a/BeefLibs/corlib/src/IO/FileStream.bf b/BeefLibs/corlib/src/IO/FileStream.bf index 0be6c773..de46955a 100644 --- a/BeefLibs/corlib/src/IO/FileStream.bf +++ b/BeefLibs/corlib/src/IO/FileStream.bf @@ -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 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 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()