Skip to content

API Proposal: File.ReadLinesAsync #2214

@khellang

Description

@khellang

Now that IAsyncEnumerable<T> has landed, I'd like to propose the following new methods to the File type:

namespace System.IO {
    public static partial class File {
        public static System.Collections.Generic.IEnumerable<string> ReadLines(string path) { throw null; }
        public static System.Collections.Generic.IEnumerable<string> ReadLines(string path, System.Text.Encoding encoding) { throw null; }
+       public static System.Collections.Generic.IAsyncEnumerable<string> ReadLinesAsync(string path, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
+       public static System.Collections.Generic.IAsyncEnumerable<string> ReadLinesAsync(string path, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
    }
}

The methods would basically be async counterparts to File.ReadLines, so they would mirror what File.ReadAllLinesAsync does, i.e. use an asynchronous, sequential StreamReader, but read line by line lazily, without allocating a list or array.

These would fill the remaining gap for async reading done by the File type, as mentioned in https://github.com/dotnet/corefx/issues/11220.

Metadata

Metadata

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.IOhelp wanted[up-for-grabs] Good issue for external contributors

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions