DotNext by .NET Foundation and Contributors

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

 StreamConsumer

Represents implementation of IReadOnlySpanConsumer<T> in the form of the writer to Stream.
using DotNext.Buffers; using DotNext.Runtime.CompilerServices; using System; using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; namespace DotNext.IO { [StructLayout(LayoutKind.Auto)] public readonly struct StreamConsumer : IReadOnlySpanConsumer<byte>, ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask>>, IEquatable<StreamConsumer>, IFlushable { private readonly Stream output; public bool IsEmpty => output == null; [NullableContext(1)] public StreamConsumer(Stream output) { if (output == null) throw new ArgumentNullException("output"); this.output = output; } void IReadOnlySpanConsumer<byte>.Invoke(ReadOnlySpan<byte> input) { output.Write(input); } ValueTask ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>.Invoke(ReadOnlyMemory<byte> input, CancellationToken token) { return output.WriteAsync(input, token); } Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask> IFunctional<Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask>>.ToDelegate() { Stream stream = output; return stream.WriteAsync; } void IFlushable.Flush() { output.Flush(); } Task IFlushable.FlushAsync(CancellationToken token) { return output.FlushAsync(token); } [NullableContext(2)] public override string ToString() { return output?.ToString(); } public static implicit operator StreamConsumer(Stream output) { return new StreamConsumer(output); } [CompilerGenerated] private bool PrintMembers(StringBuilder builder) { builder.Append("IsEmpty = "); builder.Append(IsEmpty.ToString()); return true; } public static bool operator !=(StreamConsumer left, StreamConsumer right) { return !(left == right); } public static bool operator ==(StreamConsumer left, StreamConsumer right) { return left.Equals(right); } [CompilerGenerated] public override int GetHashCode() { return EqualityComparer<Stream>.Default.GetHashCode(output); } [CompilerGenerated] public override bool Equals(object obj) { if (obj is StreamConsumer) return Equals((StreamConsumer)obj); return false; } [CompilerGenerated] public bool Equals(StreamConsumer other) { return EqualityComparer<Stream>.Default.Equals(output, other.output); } [NullableContext(1)] [CompilerGenerated] public void Deconstruct(out Stream output) { output = this.output; } } }