namespace PacketIO; public class PacketFile : IPacketFile { private string fileName; private TempFile? tempFile; private Stream stream; public PacketFile(string fileName) { this.fileName = fileName; this.tempFile = new TempFile(); this.stream = tempFile.Open(FileMode.Open); } public PacketFile(string fileName, Stream stream) { this.fileName = fileName; this.stream = stream; } public IEnumerable EnumerableFiles() { return []; } public string GetFileName() { return this.fileName; } public long GetFileSize() { return this.stream.Length; } public PacketFileType GetFileType() { return PacketFileType.File; } public async ValueTask ReadAsync(byte[] buffer, int offset, int count) { int read = await this.stream.ReadAsync(buffer, offset, count).ConfigureAwait(false); return read; } public async ValueTask WriteAsync(byte[] buffer, int offset, int count) { await this.stream.WriteAsync(buffer, offset, count).ConfigureAwait(false); } public void Seek(long offset, SeekOrigin origin) { this.stream.Seek(offset, origin); } public void Dispose() { this.stream.Dispose(); if (this.tempFile is object) { this.tempFile.Dispose(); } } }