DotNext by .NET Foundation and Contributors

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

 ReadOnlyMemoryStream

using DotNext.Buffers; using System; using System.Buffers; using System.IO; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; namespace DotNext.IO { internal sealed class ReadOnlyMemoryStream : ReadOnlyStream { [CompilerGenerated] private ReadOnlySequence<byte> <sequence>P = sequence; private SequencePosition position = <sequence>P.Start; private ReadOnlySequence<byte> RemainingSequence => <sequence>P.Slice(position); public override bool CanSeek => true; public override long Length => <sequence>P.Length; public override long Position { get { return <sequence>P.GetOffset(position); } set { ArgumentOutOfRangeException.ThrowIfGreaterThan<ulong>((ulong)value, (ulong)<sequence>P.Length, "value"); position = <sequence>P.GetPosition(value); } } public ReadOnlyMemoryStream(ReadOnlySequence<byte> sequence) { } [AsyncStateMachine(typeof(<CopyToAsync>d__12))] public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken token) { <CopyToAsync>d__12 stateMachine = default(<CopyToAsync>d__12); stateMachine.<>t__builder = AsyncTaskMethodBuilder.Create(); stateMachine.<>4__this = this; stateMachine.destination = destination; stateMachine.bufferSize = bufferSize; stateMachine.token = token; stateMachine.<>1__state = -1; stateMachine.<>t__builder.Start(ref stateMachine); return stateMachine.<>t__builder.Task; } public override void CopyTo(Stream destination, int bufferSize) { Stream.ValidateCopyToArguments(destination, bufferSize); ReadOnlySequence<byte>.Enumerator enumerator = RemainingSequence.GetEnumerator(); while (enumerator.MoveNext()) { destination.Write(enumerator.Current.Span); } position = <sequence>P.End; } public override void SetLength(long value) { ReadOnlySequence<byte> readOnlySequence = <sequence>P.Slice(0, value); position = readOnlySequence.GetPosition(Math.Min(<sequence>P.GetOffset(position), readOnlySequence.Length)); <sequence>P = readOnlySequence; } public override int Read(Span<byte> buffer) { ReadOnlySequence<byte> source = RemainingSequence; ref source.CopyTo(buffer, out int writtenCount); position = <sequence>P.GetPosition(writtenCount, position); return writtenCount; } public override long Seek(long offset, SeekOrigin origin) { long num; switch (origin) { case SeekOrigin.Begin: num = offset; break; case SeekOrigin.Current: num = <sequence>P.GetOffset(position) + offset; break; case SeekOrigin.End: num = <sequence>P.Length + offset; break; default: throw new ArgumentOutOfRangeException("origin"); } long num2 = num; if (num2 < 0) throw new IOException(); ArgumentOutOfRangeException.ThrowIfGreaterThan<long>(num2, <sequence>P.Length, "offset"); position = <sequence>P.GetPosition(num2); return num2; } public override string ToString() { return <sequence>P.ToString(); } } }