2024-06-01 12:28:32 +09:00
|
|
|
namespace PacketIO;
|
|
|
|
|
|
|
|
public class PacketFile : IPacketFile
|
|
|
|
{
|
|
|
|
private string fileName;
|
2024-06-01 20:40:56 +09:00
|
|
|
private TempFile? tempFile;
|
2024-06-01 12:28:32 +09:00
|
|
|
private Stream stream;
|
|
|
|
|
|
|
|
public PacketFile(string fileName)
|
|
|
|
{
|
|
|
|
this.fileName = fileName;
|
2024-06-01 20:40:56 +09:00
|
|
|
this.tempFile = new TempFile();
|
|
|
|
this.stream = tempFile.Open(FileMode.Open);
|
2024-06-01 12:28:32 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public PacketFile(string fileName, Stream stream)
|
|
|
|
{
|
|
|
|
this.fileName = fileName;
|
|
|
|
this.stream = stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<IPacketFile> EnumerableFiles()
|
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public string GetFileName()
|
|
|
|
{
|
|
|
|
return this.fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long GetFileSize()
|
|
|
|
{
|
|
|
|
return this.stream.Length;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PacketFileType GetFileType()
|
|
|
|
{
|
|
|
|
return PacketFileType.File;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async ValueTask<int> 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();
|
2024-06-01 20:40:56 +09:00
|
|
|
if (this.tempFile is object)
|
|
|
|
{
|
|
|
|
this.tempFile.Dispose();
|
|
|
|
}
|
2024-06-01 12:28:32 +09:00
|
|
|
}
|
|
|
|
}
|