Skip to content

Commit

Permalink
Merge branch 'netstandard' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisaAkiron authored Sep 22, 2021
2 parents 68db1b4 + 36da638 commit dc60b05
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions CmlLib/Utils/IOUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static async Task<string> ReadFileAsync(string path)
using var reader = AsyncStreamReader(path, Encoding.UTF8);
var content = await reader.ReadToEndAsync()
.ConfigureAwait(false); // **MUST be awaited in this scope**
await disposeStreamAsync(reader.BaseStream).ConfigureAwait(false);
await reader.BaseStream.FlushAsync().ConfigureAwait(false);
return content;
}

Expand All @@ -190,30 +190,19 @@ public static async Task WriteFileAsync(string path, string content)
{
// UTF8 with BOM might not be recognized by minecraft. not tested
var encoder = new UTF8Encoding(false);
var writer = AsyncStreamWriter(path, encoder, false);
using var writer = AsyncStreamWriter(path, encoder, false);
await writer.WriteAsync(content).ConfigureAwait(false); // **MUST be awaited in this scope**
await writer.FlushAsync().ConfigureAwait(false);
writer.Dispose();
}

public static async Task CopyFileAsync(string sourceFile, string destinationFile)
{
var sourceStream = AsyncReadStream(sourceFile);
var destinationStream = AsyncWriteStream(destinationFile, false);
using var sourceStream = AsyncReadStream(sourceFile);
using var destinationStream = AsyncWriteStream(destinationFile, false);

await sourceStream.CopyToAsync(destinationStream).ConfigureAwait(false);

await destinationStream.FlushAsync().ConfigureAwait(false);

await disposeStreamAsync(sourceStream).ConfigureAwait(false);
await disposeStreamAsync(destinationStream).ConfigureAwait(false);
}

private static async Task disposeStreamAsync(Stream stream)
{
stream.Dispose();
return Task.CompletedTask;
await stream.FlushAsync().ConfigureAwait(false);
stream.Dispose();
}

#endregion
Expand Down

0 comments on commit dc60b05

Please sign in to comment.