namespace StorageServer.IO; public class TempFile : IDisposable { public string FileName { get; } public TempFile() { this.FileName = Path.GetTempFileName(); } public FileStream Open() { return new FileStream(this.FileName, FileMode.Open); } public async Task CopyToAsync(Stream stream) { FileStream fs = this.Open(); await fs.CopyToAsync(stream); return fs; } public void Dispose() { try { File.Delete(this.FileName); } catch (Exception) { // unhandled exception error. } } }