Skip to content

Commit

Permalink
Merge pull request #23 from rameel/cleanup
Browse files Browse the repository at this point in the history
Replace indirect OpenReadAsync calls with direct calls
  • Loading branch information
rameel authored Sep 12, 2024
2 parents 9d79345 + f1a320d commit 17426b9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Ramstack.FileSystem.Abstractions/VirtualFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public static async ValueTask<string> ReadAllTextAsync(this VirtualFile file, En
{
const int BufferSize = 4096;

var reader = await file.OpenTextAsync(encoding, cancellationToken).ConfigureAwait(false);
var stream = await file.OpenReadAsync(cancellationToken).ConfigureAwait(false);
var reader = new StreamReader(stream, encoding);
var buffer = (char[]?)null;

try
Expand Down Expand Up @@ -124,7 +125,8 @@ public static ValueTask<string[]> ReadAllLinesAsync(this VirtualFile file, Cance
/// </returns>
public static async ValueTask<string[]> ReadAllLinesAsync(this VirtualFile file, Encoding encoding, CancellationToken cancellationToken = default)
{
using var reader = await file.OpenTextAsync(encoding, cancellationToken).ConfigureAwait(false);
var stream = await file.OpenReadAsync(cancellationToken).ConfigureAwait(false);
using var reader = new StreamReader(stream, encoding);

var list = new List<string>();
while (await reader.ReadLineAsync().ConfigureAwait(false) is {} line)
Expand Down Expand Up @@ -307,7 +309,7 @@ public static async ValueTask WriteAllTextAsync(this VirtualFile file, ReadOnlyM

var preamble = encoding.GetPreamble();
if (preamble.Length != 0)
stream.Write(preamble);
stream.Write(preamble.AsSpan());

var bytes = ArrayPool<byte>.Shared.Rent(
encoding.GetMaxCharCount(Math.Min(ChunkSize, contents.Length)));
Expand Down

0 comments on commit 17426b9

Please sign in to comment.