Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/Polyfill/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,13 @@ public static async Task<string[]> ReadAllLinesAsync(string path, Encoding encod
var lines = new List<string>();
using var reader = AsyncStreamReader(path, encoding);

while (!reader.EndOfStream)
// Reading until ReadLineAsync returns null, rather than testing EndOfStream before each
// line, keeps every read asynchronous: EndOfStream refills an empty buffer with a blocking read.
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
lines.Add(line);
}
lines.Add(line);
}

return lines.ToArray();
Expand Down Expand Up @@ -363,14 +362,13 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
// Reading until ReadLineAsync returns null, rather than testing EndOfStream before each
// line, keeps every read asynchronous: EndOfStream refills an empty buffer with a blocking read.
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}

Expand Down
18 changes: 6 additions & 12 deletions src/Split/net461/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ public static async Task<string[]> ReadAllLinesAsync(string path, Encoding encod
{
var lines = new List<string>();
using var reader = AsyncStreamReader(path, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
lines.Add(line);
}
lines.Add(line);
}
return lines.ToArray();
}
Expand Down Expand Up @@ -273,14 +270,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
18 changes: 6 additions & 12 deletions src/Split/net462/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ public static async Task<string[]> ReadAllLinesAsync(string path, Encoding encod
{
var lines = new List<string>();
using var reader = AsyncStreamReader(path, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
lines.Add(line);
}
lines.Add(line);
}
return lines.ToArray();
}
Expand Down Expand Up @@ -273,14 +270,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
18 changes: 6 additions & 12 deletions src/Split/net47/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ public static async Task<string[]> ReadAllLinesAsync(string path, Encoding encod
{
var lines = new List<string>();
using var reader = AsyncStreamReader(path, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
lines.Add(line);
}
lines.Add(line);
}
return lines.ToArray();
}
Expand Down Expand Up @@ -273,14 +270,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
18 changes: 6 additions & 12 deletions src/Split/net471/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ public static async Task<string[]> ReadAllLinesAsync(string path, Encoding encod
{
var lines = new List<string>();
using var reader = AsyncStreamReader(path, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
lines.Add(line);
}
lines.Add(line);
}
return lines.ToArray();
}
Expand Down Expand Up @@ -273,14 +270,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
18 changes: 6 additions & 12 deletions src/Split/net472/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ public static async Task<string[]> ReadAllLinesAsync(string path, Encoding encod
{
var lines = new List<string>();
using var reader = AsyncStreamReader(path, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
lines.Add(line);
}
lines.Add(line);
}
return lines.ToArray();
}
Expand Down Expand Up @@ -273,14 +270,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
18 changes: 6 additions & 12 deletions src/Split/net48/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ public static async Task<string[]> ReadAllLinesAsync(string path, Encoding encod
{
var lines = new List<string>();
using var reader = AsyncStreamReader(path, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
lines.Add(line);
}
lines.Add(line);
}
return lines.ToArray();
}
Expand Down Expand Up @@ -273,14 +270,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
18 changes: 6 additions & 12 deletions src/Split/net481/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,11 @@ public static async Task<string[]> ReadAllLinesAsync(string path, Encoding encod
{
var lines = new List<string>();
using var reader = AsyncStreamReader(path, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
lines.Add(line);
}
lines.Add(line);
}
return lines.ToArray();
}
Expand Down Expand Up @@ -273,14 +270,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
9 changes: 3 additions & 6 deletions src/Split/net5.0/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
9 changes: 3 additions & 6 deletions src/Split/net6.0/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
9 changes: 3 additions & 6 deletions src/Split/netcoreapp2.0/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
9 changes: 3 additions & 6 deletions src/Split/netcoreapp2.1/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
9 changes: 3 additions & 6 deletions src/Split/netcoreapp2.2/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
9 changes: 3 additions & 6 deletions src/Split/netcoreapp3.0/FilePolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,11 @@ public static async IAsyncEnumerable<string> ReadLinesAsync(string path, Encodin
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
using var reader = new StreamReader(stream, encoding);
while (!reader.EndOfStream)
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
cancellationToken.ThrowIfCancellationRequested();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
if (line != null)
{
yield return line;
}
yield return line;
}
}
#endif
Expand Down
Loading
Loading