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

namespace skyscraper5.Skyscraper.Scraper.Utils
{
    class PacketDumper : ITsPacketProcessor
    {
        private readonly FileStream outputFile;

        public PacketDumper(FileInfo outFile)
        {
            if (outFile.Exists)
                outFile.Delete();

            outputFile = outFile.OpenWrite();
        }

        public void PushPacket(TsPacket packet)
        {
            Span<byte> payload = packet.GetPayload();

            outputFile.Write(payload.ToArray(), 0, payload.Length);
            outputFile.Flush();
        }
    }
}
