using System.Diagnostics;
using System.Text.Json;
namespace WarcatExample;
class Decode
{
public static void Run()
{
var options = Message.Options();
using (var process = new Process())
{
process.StartInfo.FileName = "warcat";
process.StartInfo.ArgumentList.Add("export");
process.StartInfo.ArgumentList.Add("--input=example.warc");
process.StartInfo.ArgumentList.Add("--format=jsonl");
process.StartInfo.RedirectStandardOutput = true;
process.Start();
while (true)
{
var line = process.StandardOutput.ReadLine();
if (line == null)
{
break;
}
var message = JsonSerializer.Deserialize<Message>(line, options)!;
if (message.Header != null)
{
foreach (var field in message.Header.Fields)
{
Console.WriteLine($"{field[0]}:{field[1]}");
}
}
else if (message.BlockChunk != null)
{
Console.WriteLine($"{message.BlockChunk.Data.Length}");
}
else if (message.EndOfFile != null)
{
Console.WriteLine("---");
}
}
}
}
}