using System.IO.Pipelines;
Pipe pipe = new(new(System.Buffers.MemoryPool<byte>.Shared));
HttpClient client = new();
var response = await client.GetAsync("http://example.com");
var memory = (await response.Content.ReadAsByteArrayAsync()).AsMemory();
var index = memory.Length / 2;
var p1 = memory[..index];
var p2 = memory[index..];
for (int i = 0; i < 110; i++)
var pipeMemory = pipe.Writer.GetMemory(p1.Length);
Console.WriteLine($"advancing {p1.Length}");
pipe.Writer.Advance(p1.Length);
pipeMemory = pipe.Writer.GetMemory(p2.Length);
Console.WriteLine($"advancing {p2.Length}");
pipe.Writer.Advance(p2.Length);
Console.WriteLine("flushing");
await pipe.Writer.FlushAsync();
Console.WriteLine("finished flushing");
var result = await pipe.Reader.ReadAsync();
foreach (var bufferMemory in result.Buffer)
Console.Write(System.Text.Encoding.UTF8.GetString(bufferMemory.Span));
pipe.Reader.AdvanceTo(result.Buffer.End);