using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace skyscraper5.Hdmv
{
    internal class M2TsToTs
    {
        public FileInfo Infile { get; }
        public FileInfo Outfile { get; }

        public M2TsToTs(FileInfo infile, FileInfo outfile)
        {
            Infile = infile;
            Outfile = outfile;
        }

        public void Run()
        {
            FileStream inStream = Infile.OpenRead();
            FileStream outStream = Outfile.OpenWrite();
            HdmvReader hdmvReader = new HdmvReader(inStream);
            byte[] buffer;

            while (true)
            {
                byte[] readPacket = hdmvReader.ReadPacket();
                if (readPacket != null)
                    outStream.Write(readPacket, 0, 188);
                else
                    break;
            }
            inStream.Close();
            outStream.Flush();
            outStream.Close();
        }
    }
}
