StorageServer/IO/TempFile.cs

26 lines
616 B
C#
Raw Normal View History

2024-03-24 10:29:56 +09:00
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<FileStream> 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.
}
}
}