Skip to content
Merged
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
12 changes: 8 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/IO/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ private static async Task InternalWriteAllLinesAsync(TextWriter writer, IEnumera

private static async Task InternalWriteAllTextAsync(StreamWriter sw, string contents, CancellationToken cancellationToken)
{
#if MS_IO_REDIST
char[]? buffer = null;
try
{
Expand All @@ -931,11 +932,7 @@ private static async Task InternalWriteAllTextAsync(StreamWriter sw, string cont
{
int batchSize = Math.Min(DefaultBufferSize, count - index);
contents.CopyTo(index, buffer, 0, batchSize);
#if MS_IO_REDIST
await sw.WriteAsync(buffer, 0, batchSize).ConfigureAwait(false);
#else
await sw.WriteAsync(new ReadOnlyMemory<char>(buffer, 0, batchSize), cancellationToken).ConfigureAwait(false);
#endif
index += batchSize;
}

Expand All @@ -950,6 +947,13 @@ private static async Task InternalWriteAllTextAsync(StreamWriter sw, string cont
ArrayPool<char>.Shared.Return(buffer);
}
}
#else
using (sw)
{
await sw.WriteAsync(contents.AsMemory(), cancellationToken).ConfigureAwait(false);
await sw.FlushAsync().ConfigureAwait(false);
}
#endif
}

public static Task AppendAllTextAsync(string path, string? contents, CancellationToken cancellationToken = default(CancellationToken))
Expand Down