Skip to content

[API Proposal]: Add FileStream.DefaultBufferSize #128613

@Neme12

Description

@Neme12

Background and motivation

FileStream has a few constructors with a non-optional bufferSize, and there is currently no way to pass a value (either 0 or -1) to get the default behavior, as in constructors that do not take it. That's why I propose just exposing the DefaultBufferSize so that we don't have to hardcode 4096 everywhere, because that is the current default.

API Proposal

namespace System.IO;

public partial class FileStream : Stream
{
	public const int DefaultBufferSize = 4096;
    // or
    public static int DefaultBufferSize { get; }
}

API Usage

using var fileStrem = new FileStream(
	fileHandle,
	FileAccess.Read,
	FileStream.DefaultBuffersize,
	isAsync: true);

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.IO

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions