|
@@ -253,6 +253,22 @@ namespace System.IO
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public override bool CanRead
|
|
|
|
+ {
|
|
|
|
+ get
|
|
|
|
+ {
|
|
|
|
+ return mFileAccess.HasFlag(FileAccess.Read);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public override bool CanWrite
|
|
|
|
+ {
|
|
|
|
+ get
|
|
|
|
+ {
|
|
|
|
+ return mFileAccess.HasFlag(FileAccess.Write);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public this()
|
|
public this()
|
|
{
|
|
{
|
|
|
|
|
|
@@ -274,22 +290,6 @@ namespace System.IO
|
|
mFileAccess = access;
|
|
mFileAccess = access;
|
|
}
|
|
}
|
|
|
|
|
|
- public override bool CanRead
|
|
|
|
- {
|
|
|
|
- get
|
|
|
|
- {
|
|
|
|
- return mFileAccess.HasFlag(FileAccess.Read);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public override bool CanWrite
|
|
|
|
- {
|
|
|
|
- get
|
|
|
|
- {
|
|
|
|
- return mFileAccess.HasFlag(FileAccess.Write);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public Result<void, FileOpenError> Create(StringView path, FileAccess access = .ReadWrite, FileShare share = .None, int bufferSize = 4096, FileOptions options = .None, SecurityAttributes* secAttrs = null)
|
|
public Result<void, FileOpenError> Create(StringView path, FileAccess access = .ReadWrite, FileShare share = .None, int bufferSize = 4096, FileOptions options = .None, SecurityAttributes* secAttrs = null)
|
|
{
|
|
{
|
|
return Open(path, FileMode.Create, access, share, bufferSize, options, secAttrs);
|
|
return Open(path, FileMode.Create, access, share, bufferSize, options, secAttrs);
|
|
@@ -406,15 +406,20 @@ namespace System.IO
|
|
mUnderlyingLength = Platform.BfpFile_GetFileSize(mBfpFile);
|
|
mUnderlyingLength = Platform.BfpFile_GetFileSize(mBfpFile);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ protected Result<void> SeekUnderlying(int64 offset, Platform.BfpFileSeekKind seekKind = .Absolute)
|
|
|
|
+ {
|
|
|
|
+ int64 newPos = Platform.BfpFile_Seek(mBfpFile, offset, seekKind);
|
|
|
|
+ Result<void> result = ((seekKind == .Absolute) && (newPos != offset)) ? .Err : .Ok;
|
|
|
|
+ if (result case .Ok)
|
|
|
|
+ mBfpFilePos = newPos;
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
protected override Result<int> TryReadUnderlying(int64 pos, Span<uint8> data)
|
|
protected override Result<int> TryReadUnderlying(int64 pos, Span<uint8> data)
|
|
{
|
|
{
|
|
if (mBfpFilePos != pos)
|
|
if (mBfpFilePos != pos)
|
|
- {
|
|
|
|
- int64 newPos = Platform.BfpFile_Seek(mBfpFile, pos, .Absolute);
|
|
|
|
- if (newPos != pos)
|
|
|
|
- return .Err;
|
|
|
|
- mBfpFilePos = pos;
|
|
|
|
- }
|
|
|
|
|
|
+ Try!(SeekUnderlying(pos));
|
|
|
|
+
|
|
Platform.BfpFileResult result = .Ok;
|
|
Platform.BfpFileResult result = .Ok;
|
|
int numBytesRead = Platform.BfpFile_Read(mBfpFile, data.Ptr, data.Length, -1, &result);
|
|
int numBytesRead = Platform.BfpFile_Read(mBfpFile, data.Ptr, data.Length, -1, &result);
|
|
if ((result != .Ok) && (result != .PartialData))
|
|
if ((result != .Ok) && (result != .PartialData))
|
|
@@ -426,12 +431,8 @@ namespace System.IO
|
|
protected override Result<int> TryWriteUnderlying(int64 pos, Span<uint8> data)
|
|
protected override Result<int> TryWriteUnderlying(int64 pos, Span<uint8> data)
|
|
{
|
|
{
|
|
if (mBfpFilePos != pos)
|
|
if (mBfpFilePos != pos)
|
|
- {
|
|
|
|
- int64 newPos = Platform.BfpFile_Seek(mBfpFile, pos, .Absolute);
|
|
|
|
- if (newPos != pos)
|
|
|
|
- return .Err;
|
|
|
|
- mBfpFilePos = pos;
|
|
|
|
- }
|
|
|
|
|
|
+ Try!(SeekUnderlying(pos));
|
|
|
|
+
|
|
Platform.BfpFileResult result = .Ok;
|
|
Platform.BfpFileResult result = .Ok;
|
|
int numBytesRead = Platform.BfpFile_Write(mBfpFile, data.Ptr, data.Length, -1, &result);
|
|
int numBytesRead = Platform.BfpFile_Write(mBfpFile, data.Ptr, data.Length, -1, &result);
|
|
if ((result != .Ok) && (result != .PartialData))
|
|
if ((result != .Ok) && (result != .PartialData))
|
|
@@ -443,12 +444,7 @@ namespace System.IO
|
|
public Result<int> TryRead(Span<uint8> data, int timeoutMS)
|
|
public Result<int> TryRead(Span<uint8> data, int timeoutMS)
|
|
{
|
|
{
|
|
if (mBfpFilePos != mPos)
|
|
if (mBfpFilePos != mPos)
|
|
- {
|
|
|
|
- int64 newPos = Platform.BfpFile_Seek(mBfpFile, mPos, .Absolute);
|
|
|
|
- if (newPos != mPos)
|
|
|
|
- return .Err;
|
|
|
|
- mBfpFilePos = mPos;
|
|
|
|
- }
|
|
|
|
|
|
+ Try!(SeekUnderlying(mPos));
|
|
|
|
|
|
Platform.BfpFileResult result = .Ok;
|
|
Platform.BfpFileResult result = .Ok;
|
|
int numBytesRead = Platform.BfpFile_Read(mBfpFile, data.Ptr, data.Length, timeoutMS, &result);
|
|
int numBytesRead = Platform.BfpFile_Read(mBfpFile, data.Ptr, data.Length, timeoutMS, &result);
|