Skip to content

PipeReader.ReadAsync can return empty segments #30786

@Trolldemorted

Description

@Trolldemorted

I just noticed that segments in a ReadResult can be empty:

grafik
I assumed that the first segment was never empty, so I often use result.Buffer.First.Span[0]; to access the first byte.

Is this intended behaviour? Can this be caused by me writing to the pipe in a wrong way? This is how I fill my pipe from a System.IO.Compression.DeflateStream:

private async Task Decompress(PipeWriter writer, ReadOnlyMemory<byte> data, int count)
{
    InflateInputStream.Position = 0;
    InflateInputStream.Write(data.Span.Slice(0, count));
    InflateInputStream.Position = 0;
    InflateInputStream.SetLength(count);
    int read;

    do
    {
        Memory<byte> memory = writer.GetMemory(data.Length * 2);
        read = InflateOutputStream.Read(memory.Span);
        writer.Advance(read);
    }
    while (read != 0);
    await writer.FlushAsync();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions