Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​IO.​Pipelines.​PipeWriter
Assembly: System.IO.Pipelines
Inheritance: object → PipeWriter
Implemented Interfaces
Defines a class that provides a pipeline to which data can be written.
Properties
public
bool
CanGetUnflushedBytes
Gets a value that indicates whether the current <see cref="T:System.IO.Pipelines.PipeWriter" /> supports reporting the count of unflushed bytes.
public
long
UnflushedBytes
When overridden in a derived class, gets the count of unflushed bytes within the current writer.
Methods
public
void
Advance​(int bytes)
Notifies the <see cref="T:System.IO.Pipelines.PipeWriter" /> that <paramref name="bytes" /> bytes were written to the output <see cref="T:System.Span`1" /> or <see cref="T:System.Memory`1" /> . You must call <see cref="M:System.IO.Pipelines.PipeWriter.GetSpan(System.Int32)" /> or <see cref="M:System.IO.Pipelines.PipeWriter.GetMemory(System.Int32)" /> again and use the returned buffer to continue writing more data after calling <see cref="M:System.IO.Pipelines.PipeWriter.Advance(System.Int32)" /> ; you cannot write to a previously acquired buffer.
bytes
The number of bytes written to the <see cref="T:System.Span`1" /> or <see cref="T:System.Memory`1" /> .
public
Stream
AsStream​(bool leaveOpen = false)
Returns a <see cref="T:System.IO.Stream" /> representation of the <see cref="T:System.IO.Pipelines.PipeWriter" /> .
Returns A stream that represents the <see cref="T:System.IO.Pipelines.PipeWriter" /> .
leaveOpen
An optional flag that indicates whether disposing the returned <see cref="T:System.IO.Stream" /> leaves <see cref="T:System.IO.Pipelines.PipeReader" /> open ( <see langword="true" /> ) or completes <see cref="T:System.IO.Pipelines.PipeReader" /> ( <see langword="false" /> ).
public
void
CancelPendingFlush​()
Cancels the pending <see cref="M:System.IO.Pipelines.PipeWriter.FlushAsync(System.Threading.CancellationToken)" /> or <see cref="M:System.IO.Pipelines.PipeWriter.WriteAsync(System.ReadOnlyMemory{System.Byte},System.Threading.CancellationToken)" /> operation without causing the operation to throw and without completing the <see cref="T:System.IO.Pipelines.PipeWriter" /> . If there is no pending operation, this cancels the next operation.
public
void
Complete​(Exception exception = null)
Marks the <see cref="T:System.IO.Pipelines.PipeWriter" /> as being complete, meaning no more items will be written to it.
exception
Optional <see cref="T:System.Exception" /> indicating a failure that's causing the pipeline to complete.
CompleteAsync​(Exception exception = null)
Marks the current pipe writer instance as being complete, meaning no more data will be written to it.
Returns A value task that represents the asynchronous complete operation.
exception
An optional exception that indicates the failure that caused the pipeline to complete.
public static
PipeWriter
Create​(Stream stream,
StreamPipeWriterOptions? writerOptions = null)
Creates a <see cref="T:System.IO.Pipelines.PipeWriter" /> wrapping the specified <see cref="T:System.IO.Stream" /> .
Returns A <see cref="T:System.IO.Pipelines.PipeWriter" /> that wraps the <see cref="T:System.IO.Stream" /> .
stream
The stream that the pipe writer will wrap.
writerOptions
The options to configure the pipe writer.
public
Threading.​Tasks.​ValueTask<​FlushResult>
FlushAsync​(Threading.​CancellationToken cancellationToken = null)
Makes bytes written available to <see cref="T:System.IO.Pipelines.PipeReader" /> and runs <see cref="M:System.IO.Pipelines.PipeReader.ReadAsync(System.Threading.CancellationToken)" /> continuation.
Returns A task that represents and wraps the asynchronous flush operation.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public
Memory<​byte>
GetMemory​(int sizeHint = 0)
Returns a <see cref="T:System.Memory`1" /> to write to that is at least the requested size, as specified by the <paramref name="sizeHint" /> parameter.
Returns A memory buffer of at least <paramref name="sizeHint" /> bytes. If <paramref name="sizeHint" /> is 0, returns a non-empty buffer of arbitrary size.
sizeHint
The minimum length of the returned <see cref="T:System.Memory`1" /> . If 0, a non-empty memory buffer of arbitrary size is returned.
public
Span<​byte>
GetSpan​(int sizeHint = 0)
Returns a <see cref="T:System.Span`1" /> to write to that is at least the requested size, as specified by the <paramref name="sizeHint" /> parameter.
Returns A buffer of at least <paramref name="sizeHint" /> bytes. If <paramref name="sizeHint" /> is 0, returns a non-empty buffer of arbitrary size.
sizeHint
The minimum length of the returned <see cref="T:System.Span`1" /> . If 0, a non-empty buffer of arbitrary size is returned.
public
void
OnReaderCompleted​(Action<​Exception, object> callback,
object state)
Registers a callback that executes when the <see cref="T:System.IO.Pipelines.PipeReader" /> side of the pipe is completed.
callback
The callback to register.
state
The state object to pass to <paramref name="callback" /> when it's invoked.
public
Threading.​Tasks.​ValueTask<​FlushResult>
WriteAsync​(ReadOnlyMemory<​byte> source,
Threading.​CancellationToken cancellationToken = null)
Writes the specified byte memory range to the pipe and makes data accessible to the <see cref="T:System.IO.Pipelines.PipeReader" /> .
Returns A task that represents the asynchronous write operation, and wraps the flush asynchronous operation.
source
The read-only byte memory region to write.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object