<PackageReference Include="System.IO.Pipelines" Version="9.0.10" />

PipeWriter

public abstract class PipeWriter : IBufferWriter<byte>
Defines a class that provides a pipeline to which data can be written.
public virtual bool CanGetUnflushedBytes { get; }

Gets a value that indicates whether the current PipeWriter supports reporting the count of unflushed bytes.

public virtual long UnflushedBytes { get; }

When overridden in a derived class, gets the count of unflushed bytes within the current writer.

protected PipeWriter()

Initializes a new instance of the class.

public static PipeWriter Create(Stream stream, StreamPipeWriterOptions writerOptions = null)

Creates a PipeWriter wrapping the specified Stream.

public abstract void Advance(int bytes)

Notifies the PipeWriter that bytes bytes were written to the output Span<T> or Memory<T>. You must call GetSpan or GetMemory again and use the returned buffer to continue writing more data after calling Advance; you cannot write to a previously acquired buffer.

public virtual Stream AsStream(bool leaveOpen = false)

Returns a Stream representation of the PipeWriter.

public abstract void CancelPendingFlush()

Cancels the pending FlushAsync or WriteAsync operation without causing the operation to throw and without completing the PipeWriter. If there is no pending operation, this cancels the next operation.

public abstract void Complete(Exception exception = null)

Marks the PipeWriter as being complete, meaning no more items will be written to it.

public virtual ValueTask CompleteAsync(Exception exception = null)

Marks the current pipe writer instance as being complete, meaning no more data will be written to it.

public abstract ValueTask<FlushResult> FlushAsync(CancellationToken cancellationToken = default)

Makes bytes written available to PipeReader and runs ReadAsync continuation.

public abstract Memory<byte> GetMemory(int sizeHint = 0)

Returns a Memory<T> to write to that is at least the requested size, as specified by the sizeHint parameter.

public abstract Span<byte> GetSpan(int sizeHint = 0)

Returns a Span<T> to write to that is at least the requested size, as specified by the sizeHint parameter.

public virtual void OnReaderCompleted(Action<Exception, object> callback, object state)

Registers a callback that executes when the PipeReader side of the pipe is completed.

public virtual ValueTask<FlushResult> WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)

Writes the specified byte memory range to the pipe and makes data accessible to the PipeReader.