using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace DPackLib
{
    public class BinSerializer
    {
        public void SerializeData(DataPackEventArgs data, string path)
        {
            var formatter = new BinaryFormatter();
            try
            {
                using (var fs = new FileStream(path, FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fs, data);
                }
            }
            catch { }
        }

        public DataPackEventArgs DeSerializeData(string path)
        {
            var formatter = new BinaryFormatter();
            DataPackEventArgs rez = null;
            try
            {
                using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
                {
                    rez = (DataPackEventArgs)formatter.Deserialize(fs);
                }
            }
            catch { }

            return rez;
        }
    }
}
