DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="3.2.0" />

 SyncWriterStream<TOutput>

sealed class SyncWriterStream<TOutput> : WriterStream<TOutput> where TOutput : IReadOnlySpanConsumer<byte>, IFlushable
using DotNext.Buffers; using System; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace DotNext.IO { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1 })] internal sealed class SyncWriterStream<TOutput> : WriterStream<TOutput> where TOutput : IReadOnlySpanConsumer<byte>, IFlushable { public override bool CanTimeout => false; internal SyncWriterStream(TOutput output) : base(output) { } [System.Runtime.CompilerServices.NullableContext(0)] public override void Write(ReadOnlySpan<byte> buffer) { output.Invoke(buffer); writtenBytes += buffer.Length; } [System.Runtime.CompilerServices.NullableContext(0)] [AsyncStateMachine(typeof(SyncWriterStream<>.<WriteAsync>d__4))] public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken token) { <WriteAsync>d__4 stateMachine = default(<WriteAsync>d__4); stateMachine.<>t__builder = AsyncValueTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.buffer = buffer; stateMachine.token = token; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start<<WriteAsync>d__4>(ref stateMachine); return stateMachine.<>t__builder.Task; } } }