Skip to content

[BUG] - StreamReaderFunc in CsvConfiguration ignores BufferSize and uses a hardcoded value instead #1003

Closed

Description

@evgenyvalavin

Description

CsvConfiguration inherits BufferSize from MiniExcelBaseConfiguration (default 1024 * 512), but the default StreamReaderFunc ignores it and hardcodes a buffer size of 1024:

public Func<Stream, StreamReader> StreamReaderFunc { get; set; } = stream => new StreamReader(stream, DefaultEncoding, true, 1024, true);
public Func<Stream, StreamWriter> StreamWriterFunc { get; set; } = stream => new StreamWriter(stream, DefaultEncoding);

Permalink to line 20

Because these are field initializers, they can't reference this.BufferSize directly, so 1024 was likely used as a placeholder. As a result, changing BufferSize on a CsvConfiguration instance has no effect on the StreamReader's (or StreamWriter's) actual buffer size, which is misleading and can hurt performance for large files.

Expected Behavior

StreamReaderFunc (and StreamWriterFunc) should use the configured BufferSize value when constructing the default StreamReader/StreamWriter.

Actual Behavior

StreamReaderFunc always uses a hardcoded buffer size of 1024, regardless of the BufferSize value set on the configuration. StreamWriterFunc similarly does not use BufferSize at all.

Workarounds

Consumers can manually override StreamReaderFunc/StreamWriterFunc to use their desired buffer size.

Environment (please fill the following information):

Additional Context

Suggested fix: Use a nullable backing field with a lazily-initialized default, so the lambda is created on first access (after BufferSize may have been customized), without needing a constructor:

private Func<Stream, StreamReader>? _streamReaderFunc;
public Func<Stream, StreamReader> StreamReaderFunc
{
    get => _streamReaderFunc ??= stream => new StreamReader(stream, DefaultEncoding, true, BufferSize, true);
    set => _streamReaderFunc = value;
}

private Func<Stream, StreamWriter>? _streamWriterFunc;
public Func<Stream, StreamWriter> StreamWriterFunc
{
    get => _streamWriterFunc ??= stream => new StreamWriter(stream, DefaultEncoding, BufferSize, true);
    set => _streamWriterFunc = value;
}

Activity

  1. evgenyvalavin commented on Sep 8, 2026

    @evgenyvalavin
    ContributorAuthor

    Reproduced on a 140 mb file using stream.Query<>(). Read speed is about 6-7 mbit/s. Takes ~4 minutes to fully query the file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions