Skip to content

Commit

Permalink
don't bother with async on the File.Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Nov 7, 2024
1 parent a582ee8 commit c445821
Showing 1 changed file with 1 addition and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task<string> GetTextAsync(string path, Stream fileStream)
{
if (!fileStream.CanSeek)
{
seekableStream = GetTemporaryFileStream();
seekableStream = new FileStream(Path.GetTempFileName(), FileMode.Create, FileAccess.Write, FileShare.None, 4096, FileOptions.DeleteOnClose | FileOptions.Asynchronous);

await fileStream.CopyToAsync(seekableStream);

Expand All @@ -38,16 +38,7 @@ public async Task<string> GetTextAsync(string path, Stream fileStream)
if (seekableStream != null)
{
await seekableStream.DisposeAsync();

await Task.Run(() => File.Delete(seekableStream.Name));
}
}
}

private static FileStream GetTemporaryFileStream()
{
var tempFilePath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());

return new FileStream(tempFilePath, FileMode.Create, FileAccess.Write);
}
}

0 comments on commit c445821

Please sign in to comment.