26 lines
616 B
C#
26 lines
616 B
C#
|
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.
|
||
|
}
|
||
|
}
|
||
|
}
|