using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace Spherical.IO
{
    public static class Binary
    {
        public static void Writer(Stream stream, Region region)
        {
            BinaryFormatter bin = new BinaryFormatter();
            bin.Serialize(stream,region);
        }

        public static void Writer(String path, Region region)
        {
            using (FileStream stream = new FileStream(path, FileMode.Create))
            {
                Binary.Writer(stream, region);
            }
        }

        public static Region Reader(Stream stream)
        {
            BinaryFormatter bin = new BinaryFormatter();
            object o = bin.Deserialize(stream);
            Region r = o as Region;
            return r;
        }

        public static Region Reader(String path)
        {
            Region region;
            using (FileStream stream = new FileStream(path, FileMode.Open))
            {
                region = Binary.Reader(stream);
            }
            return region;
        }
    }
}
