using System.IO;

namespace Crysome.Common.Network.Packets.Server;

public class FileTransferRequestPacket : IPacket
{
	public string Filename { get; set; }

	public byte[] FileData { get; set; }

	public FileTransferRequestPacket()
	{
	}

	public FileTransferRequestPacket(string filename, byte[] fileData)
	{
		Filename = filename;
		FileData = fileData;
	}

	public void Write(BinaryWriter w)
	{
		w.Write(Filename ?? "");
		w.Write((FileData != null) ? FileData.Length : 0);
		if (FileData != null)
		{
			w.Write(FileData);
		}
	}

	public void Read(BinaryReader r)
	{
		Filename = r.ReadString();
		int count = r.ReadInt32();
		FileData = r.ReadBytes(count);
	}
}
