JobManager/ProtocolLib/PacketIO/PacketFile.cs

61 lines
1.2 KiB
C#
Raw Normal View History

2024-06-01 12:28:32 +09:00
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();
}
}