PipeWriter
Defines a class that provides a pipeline to which data can be written.
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace System.IO.Pipelines
{
public abstract class PipeWriter : IBufferWriter<byte>
{
private PipeWriterStream _stream;
public virtual bool CanGetUnflushedBytes => false;
public virtual long UnflushedBytes {
get {
throw ThrowHelper.CreateNotSupportedException_UnflushedBytes();
}
}
[System.Runtime.CompilerServices.NullableContext(2)]
public abstract void Complete(Exception exception = null);
[System.Runtime.CompilerServices.NullableContext(2)]
public virtual ValueTask CompleteAsync(Exception exception = null)
{
try {
Complete(exception);
return default(ValueTask);
} catch (Exception exception2) {
return new ValueTask(Task.FromException(exception2));
}
}
public abstract void CancelPendingFlush();
[System.Runtime.CompilerServices.NullableContext(2)]
[Obsolete("OnReaderCompleted has been deprecated and may not be invoked on all implementations of PipeWriter.")]
public virtual void OnReaderCompleted([System.Runtime.CompilerServices.Nullable(new byte[] {
1,
2,
2
})] Action<Exception, object> callback, object state)
{
}
public abstract ValueTask<FlushResult> FlushAsync(CancellationToken cancellationToken = default(CancellationToken));
public abstract void Advance(int bytes);
public abstract Memory<byte> GetMemory(int sizeHint = 0);
public abstract Span<byte> GetSpan(int sizeHint = 0);
[System.Runtime.CompilerServices.NullableContext(1)]
public virtual Stream AsStream(bool leaveOpen = false)
{
if (_stream == null)
_stream = new PipeWriterStream(this, leaveOpen);
else if (leaveOpen) {
_stream.LeaveOpen = leaveOpen;
}
return _stream;
}
[System.Runtime.CompilerServices.NullableContext(1)]
public static PipeWriter Create(Stream stream, [System.Runtime.CompilerServices.Nullable(2)] StreamPipeWriterOptions writerOptions = null)
{
return new StreamPipeWriter(stream, writerOptions ?? StreamPipeWriterOptions.s_default);
}
public virtual ValueTask<FlushResult> WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default(CancellationToken))
{
this.Write(source.Span);
return FlushAsync(cancellationToken);
}
[System.Runtime.CompilerServices.NullableContext(1)]
[AsyncStateMachine(typeof(<CopyFromAsync>d__14))]
protected internal virtual Task CopyFromAsync(Stream source, CancellationToken cancellationToken = default(CancellationToken))
{
<CopyFromAsync>d__14 stateMachine = default(<CopyFromAsync>d__14);
stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create();
stateMachine.<>4__this = this;
stateMachine.source = source;
stateMachine.cancellationToken = cancellationToken;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
}
}