61 lines
1.2 KiB
C#
61 lines
1.2 KiB
C#
|
namespace PacketIO;
|
||
|
|
||
|
public class PacketFile : IPacketFile
|
||
|
{
|
||
|
private string fileName;
|
||
|
private Stream stream;
|
||
|
|
||
|
public PacketFile(string fileName)
|
||
|
{
|
||
|
this.fileName = fileName;
|
||
|
this.stream = new MemoryStream();
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
}
|