14 [Obsolete(
"FileStream.Handle has been deprecated. Use FileStream's SafeFileHandle property instead.")]
70 [Obsolete(
"This constructor has been deprecated. Use FileStream(SafeFileHandle handle, FileAccess access) instead.")]
72 : this(
handle, access, ownsHandle: true, 4096, isAsync: false)
77 [Obsolete(
"This constructor has been deprecated. Use FileStream(SafeFileHandle handle, FileAccess access) and optionally make a new SafeFileHandle with ownsHandle=false if needed instead.")]
79 : this(
handle, access, ownsHandle, 4096, isAsync: false)
84 [Obsolete(
"This constructor has been deprecated. Use FileStream(SafeFileHandle handle, FileAccess access, int bufferSize) and optionally make a new SafeFileHandle with ownsHandle=false if needed instead.")]
86 : this(
handle, access, ownsHandle, bufferSize, isAsync: false)
91 [Obsolete(
"This constructor has been deprecated. Use FileStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync) and optionally make a new SafeFileHandle with ownsHandle=false if needed instead.")]
113 if (access < FileAccess.Read || access >
FileAccess.ReadWrite)
130 if (isAsync && !
handle.IsAsync)
134 else if (!isAsync &&
handle.IsAsync)
141 : this(
handle, access, 4096)
163 : this(path, mode, access,
FileShare.
Read, 4096, useAsync: false)
168 : this(path, mode, access, share, 4096, useAsync: false)
173 : this(path, mode, access, share, bufferSize, useAsync: false)
183 : this(path, mode, access, share, bufferSize,
options, 0
L)
193 if (path.Length == 0)
209 if (
options.PreallocationSize > 0)
223 [UnsupportedOSPlatform(
"ios")]
224 [UnsupportedOSPlatform(
"macos")]
225 [UnsupportedOSPlatform(
"tvos")]
228 if (position < 0 ||
length < 0)
239 [UnsupportedOSPlatform(
"ios")]
240 [UnsupportedOSPlatform(
"macos")]
241 [UnsupportedOSPlatform(
"tvos")]
244 if (position < 0 ||
length < 0)
362 Flush(flushToDisk:
false);
365 public virtual void Flush(
bool flushToDisk)
414 protected override void Dispose(
bool disposing)
529 return base.DisposeAsync();
static void SuppressFinalize(object obj)
int BaseEndRead(IAsyncResult asyncResult)
Task BaseCopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
int BaseRead(Span< byte > buffer)
void DisposeInternal(bool disposing)
FileStream(SafeFileHandle handle, FileAccess access)
readonly FileStreamStrategy _strategy
virtual SafeFileHandle SafeFileHandle
override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
override ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, long preallocationSize)
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override void EndWrite(IAsyncResult asyncResult)
static void ValidateHandle(SafeFileHandle handle, FileAccess access, int bufferSize)
FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options)
virtual void Unlock(long position, long length)
void BaseWrite(ReadOnlySpan< byte > buffer)
FileStream(SafeFileHandle handle, FileAccess access, int bufferSize)
ValueTask BaseDisposeAsync()
override void Dispose(bool disposing)
FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
FileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync)
FileStream(string path, FileStreamOptions options)
override ValueTask< int > ReadAsync(Memory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
override void CopyTo(Stream destination, int bufferSize)
Task< int > BaseReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override void SetLength(long value)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override int Read(Span< byte > buffer)
ValueTask< int > BaseReadAsync(Memory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
void ValidateReadWriteArgs(byte[] buffer, int offset, int count)
FileStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
override void WriteByte(byte value)
Task BaseFlushAsync(CancellationToken cancellationToken)
FileStream(IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize)
Task BaseWriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override int EndRead(IAsyncResult asyncResult)
override ValueTask DisposeAsync()
FileStream(string path, FileMode mode, FileAccess access)
override long Seek(long offset, SeekOrigin origin)
static void ValidateHandle(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
override Task FlushAsync(CancellationToken cancellationToken)
FileStream(IntPtr handle, FileAccess access)
FileStream(IntPtr handle, FileAccess access, bool ownsHandle, int bufferSize, bool isAsync)
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
override void Write(byte[] buffer, int offset, int count)
override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
FileStream(IntPtr handle, FileAccess access, bool ownsHandle)
virtual void Flush(bool flushToDisk)
override int Read(byte[] buffer, int offset, int count)
ValueTask BaseWriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
IAsyncResult BaseBeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
FileStream(string path, FileMode mode)
override void Write(ReadOnlySpan< byte > buffer)
void BaseEndWrite(IAsyncResult asyncResult)
FileStream(string path, FileMode mode, FileAccess access, FileShare share)
IAsyncResult BaseBeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
virtual void Lock(long position, long length)
static void ValidateArguments(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, long preallocationSize)
static FileStreamStrategy ChooseStrategy(FileStream fileStream, SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
static void SerializationGuard(FileAccess access)
static void ValidateArgumentsForPreallocation(FileMode mode, FileAccess access)
void Unlock(long position, long length)
void DisposeInternal(bool disposing)
void Flush(bool flushToDisk)
void Lock(long position, long length)
SafeFileHandle SafeFileHandle
static void ValidateBufferArguments(byte[] buffer, int offset, int count)
void SetLength(long value)
long Seek(long offset, SeekOrigin origin)
static void ValidateCopyToArguments(Stream destination, int bufferSize)
Task WriteAsync(byte[] buffer, int offset, int count)
virtual void EndWrite(IAsyncResult asyncResult)
int Read(byte[] buffer, int offset, int count)
void CopyTo(Stream destination)
Task< int > ReadAsync(byte[] buffer, int offset, int count)
void Write(byte[] buffer, int offset, int count)
virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
virtual void WriteByte(byte value)
virtual IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
virtual int EndRead(IAsyncResult asyncResult)
Task CopyToAsync(Stream destination)
virtual ValueTask DisposeAsync()
static string Arg_InvalidHandle
static string ArgumentOutOfRange_Enum
static string Format(string resourceFormat, object p1)
static string ArgumentNull_Path
static string Argument_InvalidFileModeAndAccessCombo
static string Argument_EmptyPath
static string Argument_InvalidAppendMode
static Task FromCanceled(CancellationToken cancellationToken)
static void ThrowNotSupportedException_UnwritableStream()
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
static void ThrowArgumentOutOfRangeException_NeedNonNegNum(string paramName)
static void ThrowArgumentException_HandleNotSync(string paramName)
static void ThrowNotSupportedException_UnseekableStream()
static void ThrowArgumentException_HandleNotAsync(string paramName)
static void ThrowObjectDisposedException_FileClosed()
static void ThrowNotSupportedException_UnreadableStream()
static ValueTask FromCanceled(CancellationToken cancellationToken)