Represents the buffered file writer.
Namespace: DotNext.IO Assembly: DotNext.IO.dll Syntaxpublic class FileWriter : Disposable, IAsyncBinaryWriter, ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask>>, IFlushable, IBufferedWriter, IBufferedChannel, IResettable, IDisposable, IBufferWriter<byte>, IDynamicInterfaceCastable
Constructors | Edit this page View Source FileWriter(SafeFileHandle)
Creates a new writer backed by the file.
Declarationpublic FileWriter(SafeFileHandle handle)
Parameters Exceptions | Edit this page View Source FileWriter(FileStream)
Creates a new writer backed by the file.
Declarationpublic FileWriter(FileStream destination)
Parameters Type Name Description FileStream destination
Writable file stream.
Exceptions Fields | Edit this page View Source handleRepresents the file handle.
Declarationprotected readonly SafeFileHandle handle
Field Value Properties | Edit this page View Source Allocator
Gets buffer allocator.
Declarationpublic MemoryAllocator<byte>? Allocator { get; init; }
Property Value | Edit this page View Source Buffer
The remaining part of the internal buffer available for write.
Declarationpublic Memory<byte> Buffer { get; }
Property Value | Edit this page View Source FilePosition
Gets or sets the cursor position within the file.
Declarationpublic long FilePosition { get; set; }
Property Value Exceptions | Edit this page View Source HasBufferedData
Gets a value indicating that this writer has buffered data.
Declarationpublic bool HasBufferedData { get; }
Property Value | Edit this page View Source MaxBufferSize
Gets the maximum size of the internal buffer.
Declarationpublic int MaxBufferSize { get; init; }
Property Value | Edit this page View Source WritePosition
Gets write position.
Declarationpublic long WritePosition { get; }
Property Value | Edit this page View Source WrittenBuffer
Gets written part of the buffer.
Declarationpublic ReadOnlyMemory<byte> WrittenBuffer { get; }
Property Value Methods | Edit this page View Source CopyFromAsync(Stream, long, CancellationToken)
Writes the content from the specified stream.
Declarationpublic ValueTask CopyFromAsync(Stream source, long count, CancellationToken token = default)
Parameters Type Name Description Stream source
The stream to read from.
long countThe number of bytes to copy.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing state of asynchronous execution.
Exceptions | Edit this page View Source CopyFromAsync(Stream, CancellationToken)Writes the content from the specified stream.
Declarationpublic ValueTask CopyFromAsync(Stream input, CancellationToken token = default)
Parameters Type Name Description Stream input
The stream to read from.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing state of asynchronous execution.
Exceptions | Edit this page View Source Dispose(bool)Releases managed and unmanaged resources associated with this object.
Declarationprotected override void Dispose(bool disposing)
Parameters Overrides | Edit this page View Source EncodeAsync(ReadOnlyMemory<char>, EncodingContext, LengthFormat?, CancellationToken)
Encodes a block of characters using the specified encoding.
Declarationpublic ValueTask<long> EncodeAsync(ReadOnlyMemory<char> chars, EncodingContext context, LengthFormat? lengthFormat, CancellationToken token = default)
Parameters Returns Exceptions | Edit this page View Source FlushToDisk()
Flushes the operating system buffers for the given file to disk.
Declarationpublic void FlushToDisk()
Exceptions | Edit this page View Source FormatAsync<T>(T, EncodingContext, LengthFormat?, string?, IFormatProvider?, MemoryAllocator<char>?, CancellationToken)
Encodes formatted value as a set of characters using the specified encoding.
Declarationpublic ValueTask<long> FormatAsync<T>(T value, EncodingContext context, LengthFormat? lengthFormat, string? format = null, IFormatProvider? provider = null, MemoryAllocator<char>? allocator = null, CancellationToken token = default) where T : ISpanFormattable
Parameters Type Name Description T value
The type value to be written as string.
EncodingContext contextThe context describing encoding of characters.
LengthFormat? lengthFormatString length encoding format; or null to prevent encoding of string length.
string formatThe format of the value.
IFormatProvider providerThe format provider.
MemoryAllocator<char> allocatorCharacters buffer allocator.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Parameters Name Description TThe type of formattable value.
Exceptions | Edit this page View Source FormatAsync<T>(T, LengthFormat?, string?, IFormatProvider?, CancellationToken)Converts the value to UTF-8 encoded characters.
Declarationpublic ValueTask<int> FormatAsync<T>(T value, LengthFormat? lengthFormat, string? format = null, IFormatProvider? provider = null, CancellationToken token = default) where T : IUtf8SpanFormattable
Parameters Type Name Description T value
The value to convert.
LengthFormat? lengthFormatString length encoding format.
string formatThe format of the value.
IFormatProvider providerThe format provider.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<int>The number of written bytes.
Type Parameters Name Description TThe type of the value to convert.
Exceptions | Edit this page View Source Produce(int)Marks the specified number of bytes in the buffer as produced.
Declarationpublic void Produce(int count)
Parameters Type Name Description int count
The number of produced bytes.
Exceptions | Edit this page View Source Reset()Drops all buffered data.
Declaration | Edit this page View Source TryWrite(ReadOnlySpan<byte>)Tries to write the data to the internal buffer.
Declarationpublic bool TryWrite(ReadOnlySpan<byte> input)
Parameters Returns Type Description bool
true if the internal buffer has enough space to place the data from input
; otherwise, false.
Flushes buffered data to the file.
Declaration Exceptions | Edit this page View Source Write(ReadOnlySpan<byte>)Writes the data to the file through the buffer.
Declarationpublic void Write(ReadOnlySpan<byte> input)
Parameters Exceptions | Edit this page View Source WriteAsync(ReadOnlyMemory<byte>, LengthFormat, CancellationToken)
Encodes a block of memory, optionally prefixed with the length encoded as a sequence of bytes according to the specified format.
Declarationpublic ValueTask WriteAsync(ReadOnlyMemory<byte> input, LengthFormat lengthFormat, CancellationToken token = default)
Parameters Returns Type Description ValueTask
The task representing state of asynchronous execution.
Exceptions | Edit this page View Source WriteAsync(ReadOnlyMemory<byte>, CancellationToken)Writes the data to the underlying storage through the buffer.
Declarationpublic ValueTask WriteAsync(ReadOnlyMemory<byte> input, CancellationToken token = default)
Parameters Returns Type Description ValueTask
The task representing asynchronous result.
Exceptions | Edit this page View Source WriteAsync(CancellationToken)Flushes buffered data to the underlying storage.
Declarationpublic ValueTask WriteAsync(CancellationToken token = default)
Parameters Type Name Description CancellationToken token
The token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing asynchronous result.
Exceptions | Edit this page View Source WriteAsync<T>(T, CancellationToken)Encodes formattable value as a set of bytes.
Declarationpublic ValueTask WriteAsync<T>(T value, CancellationToken token = default) where T : IBinaryFormattable<T>
Parameters Type Name Description T value
The value to be written as a sequence of bytes.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing state of asynchronous execution.
Type Parameters Name Description TThe type of formattable value.
Exceptions | Edit this page View Source WriteBigEndianAsync<T>(T, CancellationToken)Writes integer value in big-endian format.
Declarationpublic ValueTask WriteBigEndianAsync<T>(T value, CancellationToken token = default) where T : IBinaryInteger<T>
Parameters Type Name Description T value
The value to be written in big-endian format.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing state of asynchronous execution.
Type Parameters Name Description TThe integer type.
Exceptions | Edit this page View Source WriteLittleEndianAsync<T>(T, CancellationToken)Writes integer value in little-endian format.
Declarationpublic ValueTask WriteLittleEndianAsync<T>(T value, CancellationToken token = default) where T : IBinaryInteger<T>
Parameters Type Name Description T value
The value to be written in little-endian format.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing state of asynchronous execution.
Type Parameters Name Description TThe integer type.
Exceptions Implements Extension MethodsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4