using System.Diagnostics;
using System.IO.Hashing;
using System.Text;
using System.Text.Json;
namespace WarcatExample;
class Encode
{
public static void Run()
{
var options = Message.Options();
using (var process = new Process())
{
process.StartInfo.FileName = "warcat";
process.StartInfo.ArgumentList.Add("import");
process.StartInfo.ArgumentList.Add("--compression=none");
process.StartInfo.ArgumentList.Add("--format=jsonl");
process.StartInfo.RedirectStandardInput = true;
process.Start();
var header = new Message()
{
Header = new Header()
{
Version = "WARC/1.1",
Fields = [
["WARC-Record-Type", "resource"],
["Content-Length", "12"],
]
}
};
process.StandardInput.WriteLine(JsonSerializer.Serialize(header, options));
var hasher = new XxHash3();
var data = Encoding.UTF8.GetBytes("Hello world!");
hasher.Append(data);
var block_chunk = new Message()
{
BlockChunk = new BlockChunk()
{
Data = data
}
};
process.StandardInput.WriteLine(JsonSerializer.Serialize(block_chunk, options));
var block_end = new Message()
{
BlockEnd = new BlockEnd()
{
Xxh3 = hasher.GetCurrentHashAsUInt64()
}
};
process.StandardInput.WriteLine(JsonSerializer.Serialize(block_end, options));
process.StandardInput.WriteLine(JsonSerializer.Serialize(new Message() { EndOfFile = new EndOfFile() }, options));
}
}
}