Represents builder of contiguous block of memory that may switch to file as its backing store.
InheritanceFileBufferingWriter
Namespace: DotNext.IO Assembly: DotNext.IO.dll Syntaxpublic sealed class FileBufferingWriter : Stream, IAsyncDisposable, IBufferWriter<byte>, IGrowableBuffer<byte>, IReadOnlySpanConsumer<byte>, ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask>>, IDisposable, IResettable, IFlushable, IDynamicInterfaceCastable
Constructors | Edit this page View Source FileBufferingWriter(MemoryAllocator<byte>?, int, int, string?, bool)
Initializes a new writer.
Declarationpublic FileBufferingWriter(MemoryAllocator<byte>? allocator = null, int memoryThreshold = 32768, int initialCapacity = 0, string? tempDir = null, bool asyncIO = true)
Parameters Type Name Description MemoryAllocator<byte> allocator
The allocator of internal buffer.
int memoryThresholdThe maximum amount of memory in bytes to allocate before switching to a file on disk.
int initialCapacityInitial capacity of internal buffer. Should not be greater than memoryThreshold
.
The location of the directory to write buffered contents to. When unspecified, uses the value specified by the environment variable ASPNETCORE_TEMP
if available, otherwise uses the value returned by GetTempPath().
true if you will use asynchronous methods of the instance; otherwise, false.
Exceptions | Edit this page View Source FileBufferingWriter(in Options)Initializes a new writer.
Declarationpublic FileBufferingWriter(in FileBufferingWriter.Options options)
Parameters Exceptions Properties | Edit this page View Source CanRead
When overridden in a derived class, gets a value indicating whether the current stream supports reading.
Declarationpublic override bool CanRead { get; }
Property Value Type Description bool
true if the stream supports reading; otherwise, false.
Overrides | Edit this page View Source CanSeekWhen overridden in a derived class, gets a value indicating whether the current stream supports seeking.
Declarationpublic override bool CanSeek { get; }
Property Value Type Description bool
true if the stream supports seeking; otherwise, false.
Overrides | Edit this page View Source CanWriteWhen overridden in a derived class, gets a value indicating whether the current stream supports writing.
Declarationpublic override bool CanWrite { get; }
Property Value Type Description bool
true if the stream supports writing; otherwise, false.
Overrides | Edit this page View Source LengthWhen overridden in a derived class, gets the length in bytes of the stream.
Declarationpublic override long Length { get; }
Property Value Type Description long
A long value representing the length of the stream in bytes.
Overrides Exceptions | Edit this page View Source PositionWhen overridden in a derived class, gets or sets the position within the current stream.
Declarationpublic override long Position { get; set; }
Property Value Type Description long
The current position within the stream.
Overrides Exceptions Methods | Edit this page View Source Advance(int)Notifies the IBufferWriter<T> that count
data items were written to the output Span<T> or Memory<T>.
public void Advance(int count)
Parameters | Edit this page View Source BeginRead(byte[], int, int, AsyncCallback?, object?)
Begins an asynchronous read operation. (Consider using ReadAsync(byte[], int, int) instead.)
Declarationpublic override IAsyncResult BeginRead(byte[] data, int offset, int count, AsyncCallback? callback, object? state)
Parameters Type Name Description byte[] data int offset
The byte offset in buffer
at which to begin writing data read from the stream.
The maximum number of bytes to read.
AsyncCallback callbackAn optional asynchronous callback, to be called when the read is complete.
object stateA user-provided object that distinguishes this particular asynchronous read request from other requests.
Returns Overrides Exceptions | Edit this page View Source BeginWrite(byte[], int, int, AsyncCallback?, object?)Begins an asynchronous write operation. (Consider using WriteAsync(byte[], int, int) instead.)
Declarationpublic override IAsyncResult BeginWrite(byte[] data, int offset, int count, AsyncCallback? callback, object? state)
Parameters Type Name Description byte[] data int offset
The byte offset in buffer
from which to begin writing.
The maximum number of bytes to write.
AsyncCallback callbackAn optional asynchronous callback, to be called when the write is complete.
object stateA user-provided object that distinguishes this particular asynchronous write request from other requests.
Returns Type Description IAsyncResultAn IAsyncResult
that represents the asynchronous write, which could still be pending.
Removes all written data.
Declarationpublic void Clear(bool reuseBuffer = true)
Parameters Type Name Description bool reuseBuffer
true to keep internal buffer alive; otherwise, false.
Exceptions | Edit this page View Source CopyTo(IBufferWriter<byte>, int, CancellationToken)Drains buffered content to the buffer synchronously.
Declarationpublic void CopyTo(IBufferWriter<byte> destination, int bufferSize = 1024, CancellationToken token = default)
Parameters Type Name Description IBufferWriter<byte> destination
The buffer to drain buffered contents to.
int bufferSizeThe size, in bytes, of the buffer used to copy bytes.
CancellationToken tokenThe token to monitor for cancellation requests.
Exceptions | Edit this page View Source CopyTo(Stream, int)Drains buffered content to the stream synchronously.
Declarationpublic override void CopyTo(Stream destination, int bufferSize)
Parameters Type Name Description Stream destination
The stream to drain buffered contents to.
int bufferSizeThe size, in bytes, of the buffer used to copy bytes.
Overrides | Edit this page View Source CopyTo(Span<byte>)Drains buffered content to the memory block synchronously.
Declarationpublic int CopyTo(Span<byte> output)
Parameters Type Name Description Span<byte> output
The memory block used as a destination for copy operation.
Returns Type Description intThe actual number of copied elements.
| Edit this page View Source CopyToAsync(IBufferWriter<byte>, int, CancellationToken)Drains buffered content to the buffer asynchronously.
Declarationpublic Task CopyToAsync(IBufferWriter<byte> destination, int bufferSize = 1024, CancellationToken token = default)
Parameters Type Name Description IBufferWriter<byte> destination
The buffer to drain buffered contents to.
int bufferSizeThe size, in bytes, of the buffer used to copy bytes.
CancellationToken tokenThe token to monitor for cancellation requests.
Returns Type Description TaskThe task representing asynchronous execution of this method.
Exceptions | Edit this page View Source CopyToAsync(Stream, int, CancellationToken)Drains buffered content to the stream asynchronously.
Declarationpublic override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken token)
Parameters Type Name Description Stream destination
The stream to drain buffered contents to.
int bufferSizeThe size, in bytes, of the buffer used to copy bytes.
CancellationToken tokenThe token to monitor for cancellation requests.
Returns Type Description TaskA task that represents the asynchronous copy operation.
Overrides Exceptions | Edit this page View Source CopyToAsync(Memory<byte>, CancellationToken)Drains buffered content to the memory block asynchronously.
Declarationpublic ValueTask<int> CopyToAsync(Memory<byte> output, CancellationToken token = default)
Parameters Type Name Description Memory<byte> output
The memory block used as a destination for copy operation.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<int>The actual number of copied elements.
| Edit this page View Source CopyToAsync<TArg>(ReadOnlySpanAction<byte, TArg>, TArg, int, CancellationToken)Drains buffered content asynchronously.
Declarationpublic Task CopyToAsync<TArg>(ReadOnlySpanAction<byte, TArg> reader, TArg arg, int bufferSize = 1024, CancellationToken token = default)
Parameters Type Name Description ReadOnlySpanAction<byte, TArg> reader
The content reader.
TArg argThe argument to be passed to the callback.
int bufferSizeThe size, in bytes, of the buffer used to copy bytes.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description TaskThe task representing asynchronous execution of the operation.
Type Parameters Name Description TArgThe type of the argument to be passed to the callback.
Exceptions | Edit this page View Source CopyToAsync<TConsumer>(TConsumer, int, CancellationToken)Drains the written content to the consumer asynchronously.
Declarationpublic Task CopyToAsync<TConsumer>(TConsumer consumer, int bufferSize, CancellationToken token) where TConsumer : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
Parameters Type Name Description TConsumer consumer
The consumer of the written content.
int bufferSizeThe size, in bytes, of the buffer used to copy bytes.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description TaskThe task representing asynchronous execution of this method.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source CopyTo<TArg>(ReadOnlySpanAction<byte, TArg>, TArg, int, CancellationToken)Drains buffered content synchronously.
Declarationpublic void CopyTo<TArg>(ReadOnlySpanAction<byte, TArg> reader, TArg arg, int bufferSize = 1024, CancellationToken token = default)
Parameters Type Name Description ReadOnlySpanAction<byte, TArg> reader
The content reader.
TArg argThe argument to be passed to the callback.
int bufferSizeThe size, in bytes, of the buffer used to copy bytes.
CancellationToken tokenThe token that can be used to cancel the operation.
Type Parameters Name Description TArgThe type of the argument to be passed to the callback.
Exceptions | Edit this page View Source CopyTo<TConsumer>(TConsumer, int, CancellationToken)Drains the written content to the consumer synchronously.
Declarationpublic void CopyTo<TConsumer>(TConsumer consumer, int bufferSize, CancellationToken token) where TConsumer : IReadOnlySpanConsumer<byte>
Parameters Type Name Description TConsumer consumer
The consumer of the written content.
int bufferSizeThe size, in bytes, of the buffer used to copy bytes.
CancellationToken tokenThe token that can be used to cancel the operation.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source Dispose(bool)Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
Declarationprotected override void Dispose(bool disposing)
Parameters Type Name Description bool disposing
true to release both managed and unmanaged resources; false to release only unmanaged resources.
Overrides | Edit this page View Source EndRead(IAsyncResult)Waits for the pending asynchronous read to complete. (Consider using ReadAsync(byte[], int, int) instead.)
Declarationpublic override int EndRead(IAsyncResult asyncResult)
Parameters Type Name Description IAsyncResult asyncResult
The reference to the pending asynchronous request to finish.
Returns Type Description intThe number of bytes read from the stream, between zero (0) and the number of bytes requested. ReadAsync returns zero (0) only if zero bytes were requested or if no more bytes will be available because it's at the end of the stream; otherwise, read operations do not complete until at least one byte is available. If zero bytes are requested, read operations may complete immediately or may not complete until at least one byte is available (but without consuming any data).
Overrides Exceptions | Edit this page View Source EndWrite(IAsyncResult)Ends an asynchronous write operation. (Consider using WriteAsync(byte[], int, int) instead.)
Declarationpublic override void EndWrite(IAsyncResult ar)
Parameters Overrides Exceptions | Edit this page View Source Flush()
When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
Declarationpublic override void Flush()
Overrides Exceptions | Edit this page View Source Flush(bool)
Flushes the internal buffer with the file and optionally synchronize a file's in-core state with storage device.
Declarationpublic void Flush(bool flushToDisk)
Parameters Type Name Description bool flushToDisk
true to synchronize a file's in-core state with storage device; otherwise, false.
| Edit this page View Source FlushAsync(bool, CancellationToken)Flushes the internal buffer with the file and optionally synchronize a file's in-core state with storage device.
Declarationpublic ValueTask FlushAsync(bool flushToDisk, CancellationToken token = default)
Parameters Type Name Description bool flushToDisk
true to synchronize a file's in-core state with storage device; otherwise, false.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe asynchronous result of the operation.
Exceptions | Edit this page View Source FlushAsync(CancellationToken)Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.
Declarationpublic override Task FlushAsync(CancellationToken token)
Parameters Returns Type Description Task
A task that represents the asynchronous flush operation.
Overrides Exceptions | Edit this page View Source GetMemory(int)Returns a Memory<T> to write to that is at least the requested size (specified by sizeHint
).
public Memory<byte> GetMemory(int sizeHint = 0)
Parameters Type Name Description int sizeHint
The minimum length of the returned Memory<T>. If 0, a non-empty buffer is returned.
Returns Type Description Memory<byte>A Memory<T> of at least the size sizeHint
. If sizeHint
is 0, returns a non-empty buffer.
Returns a Span<T> to write to that is at least the requested size (specified by sizeHint
).
public Span<byte> GetSpan(int sizeHint = 0)
Parameters Type Name Description int sizeHint
The minimum length of the returned Span<T>. If 0, a non-empty buffer is returned.
Returns Type Description Span<byte>A Span<T> of at least the size sizeHint
. If sizeHint
is 0, returns a non-empty buffer.
Returns the whole buffered content as a source of Memory<T> instances synchronously.
Declarationpublic IMemoryOwner<byte> GetWrittenContent()
Returns Type Description IMemoryOwner<byte>
The memory manager providing access to buffered content.
Exceptions | Edit this page View Source GetWrittenContent(int)Gets written content in the form of ReadOnlySequence<T> synchronously.
Declarationpublic IReadOnlySequenceSource<byte> GetWrittenContent(int segmentSize)
Parameters Type Name Description int segmentSize
The size of the contiguous segment of file to be mapped to memory.
Returns Exceptions | Edit this page View Source GetWrittenContent(Range)Returns buffered content as a source of Memory<T> instances synchronously.
Declarationpublic IMemoryOwner<byte> GetWrittenContent(Range range)
Parameters Type Name Description Range range
The range of buffered content to return.
Returns Type Description IMemoryOwner<byte>The memory manager providing access to buffered content.
Exceptions | Edit this page View Source GetWrittenContentAsStream()Gets written content as read-only stream.
Declarationpublic Stream GetWrittenContentAsStream()
Returns Type Description Stream
Read-only stream representing the written content.
Exceptions | Edit this page View Source GetWrittenContentAsStreamAsync(CancellationToken)Gets written content as read-only stream asynchronously.
Declarationpublic ValueTask<Stream> GetWrittenContentAsStreamAsync(CancellationToken token = default)
Parameters Type Name Description CancellationToken token
The token that can be used to cancel the operation.
Returns Type Description ValueTask<Stream>Read-only stream representing the written content.
Exceptions | Edit this page View Source GetWrittenContentAsync(Range, CancellationToken)Returns buffered content as a source of Memory<T> instances asynchronously.
Declarationpublic ValueTask<IMemoryOwner<byte>> GetWrittenContentAsync(Range range, CancellationToken token = default)
Parameters Type Name Description Range range
The range of buffered content to return.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Exceptions | Edit this page View Source GetWrittenContentAsync(CancellationToken)Returns the whole buffered content as a source of Memory<T> instances asynchronously.
Declarationpublic ValueTask<IMemoryOwner<byte>> GetWrittenContentAsync(CancellationToken token = default)
Parameters Type Name Description CancellationToken token
The token that can be used to cancel the operation.
Returns Exceptions | Edit this page View Source Read(byte[], int, int)When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Declarationpublic override int Read(byte[] data, int offset, int count)
Parameters Type Name Description byte[] data int offset
The zero-based byte offset in buffer
at which to begin storing the data read from the current stream.
The maximum number of bytes to be read from the current stream.
Returns Type Description intThe total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if count
is 0 or the end of the stream has been reached.
When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Declarationpublic override int Read(Span<byte> data)
Parameters Returns Type Description int
The total number of bytes read into the buffer. This can be less than the size of the buffer if that many bytes are not currently available, or zero (0) if the buffer's length is zero or the end of the stream has been reached.
Overrides | Edit this page View Source ReadAsync(byte[], int, int, CancellationToken)Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
Declarationpublic override Task<int> ReadAsync(byte[] data, int offset, int count, CancellationToken token)
Parameters Type Name Description byte[] data int offset
The byte offset in buffer
at which to begin writing data from the stream.
The maximum number of bytes to read.
CancellationToken token Returns Type Description Task<int>A task that represents the asynchronous read operation. The value of the TResult
parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if count
is 0 or if the end of the stream has been reached.
Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
Declarationpublic override ValueTask<int> ReadAsync(Memory<byte> data, CancellationToken token = default)
Parameters Returns Type Description ValueTask<int>
A task that represents the asynchronous read operation. The value of its Result property contains the total number of bytes read into the buffer. The result value can be less than the length of the buffer if that many bytes are not currently available, or it can be 0 (zero) if the length of the buffer is 0 or if the end of the stream has been reached.
Overrides | Edit this page View Source ReadByte()Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
Declarationpublic override int ReadByte()
Returns Type Description int
The unsigned byte cast to an int, or -1 if at the end of the stream.
Overrides Exceptions | Edit this page View Source Seek(long, SeekOrigin)When overridden in a derived class, sets the position within the current stream.
Declarationpublic override long Seek(long offset, SeekOrigin origin)
Parameters Type Name Description long offset
A byte offset relative to the origin
parameter.
A value of type SeekOrigin indicating the reference point used to obtain the new position.
Returns Type Description longThe new position within the current stream.
Overrides Exceptions | Edit this page View Source SetLength(long)When overridden in a derived class, sets the length of the current stream.
Declarationpublic override void SetLength(long value)
Parameters Type Name Description long value
The desired length of the current stream in bytes.
Overrides Exceptions | Edit this page View Source TryGetWrittenContent(out ReadOnlyMemory<byte>)Attempts to get written content if it is located in memory.
Declarationpublic bool TryGetWrittenContent(out ReadOnlyMemory<byte> content)
Parameters Returns | Edit this page View Source TryGetWrittenContent(out ReadOnlyMemory<byte>, out string?)
Attempts to get written content if it is located in memory.
Declarationpublic bool TryGetWrittenContent(out ReadOnlyMemory<byte> content, out string? fileName)
Parameters Type Name Description ReadOnlyMemory<byte> content
The written content.
string fileNameThe path to the file used as a buffer if this writer switched to the file.
Returns | Edit this page View Source Write(byte[], int, int)When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
Declarationpublic override void Write(byte[] data, int offset, int count)
Parameters Type Name Description byte[] data int offset
The zero-based byte offset in buffer
at which to begin copying bytes to the current stream.
The number of bytes to be written to the current stream.
Overrides Exceptions | Edit this page View Source Write(ReadOnlySpan<byte>)When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
Declarationpublic override void Write(ReadOnlySpan<byte> input)
Parameters Overrides | Edit this page View Source WriteAsync(byte[], int, int, CancellationToken)
Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.
Declarationpublic override Task WriteAsync(byte[] data, int offset, int count, CancellationToken token)
Parameters Type Name Description byte[] data int offset
The zero-based byte offset in buffer
from which to begin copying bytes to the stream.
The maximum number of bytes to write.
CancellationToken token Returns Type Description TaskA task that represents the asynchronous write operation.
Overrides Exceptions | Edit this page View Source WriteAsync(ReadOnlyMemory<byte>, CancellationToken)Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.
Declarationpublic override ValueTask WriteAsync(ReadOnlyMemory<byte> input, CancellationToken token = default)
Parameters Returns Type Description ValueTask
A task that represents the asynchronous write operation.
Overrides | Edit this page View Source WriteByte(byte)Writes a byte to the current position in the stream and advances the position within the stream by one byte.
Declarationpublic override void WriteByte(byte value)
Parameters Type Name Description byte value
The byte to write to the stream.
Overrides Exceptions Implements Extension Methods StreamExtensions.ParseAsync<TArg, TResult>(Stream, TArg, ReadOnlySpanFunc<char, TArg, TResult>, DecodingContext, LengthFormat, Memory<byte>, MemoryAllocator<char>?, CancellationToken)RetroSearch 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