CheddarCrisp
·
2024-01-10
Program.cs
1SDBD.ICodec codec = new SDBD.Codec();
2
3var (encode, filepath) = ParseArgs(args);
4var inputData = File.ReadAllBytes(filepath);
5var filename = Path.GetFileName(filepath);
6
7if(encode) {
8 SDBD.Document document = new (
9 new() {
10 { "content-name", filename }
11 },
12 inputData
13 );
14 var outputData = codec.Encode(document);
15 File.WriteAllBytes($"{filename}.sdbd", outputData);
16} else {
17 var document = codec.Decode(inputData);
18 File.WriteAllBytes(document.Metadata["content-name"], document.Data);
19}
20
21(bool encode, string filepath) ParseArgs(string[] args) {
22 return args switch {
23 [var filepath] => (true, filepath),
24 ["-d", var filepath] => (false, filepath),
25 ["-e", var filepath] => (true, filepath),
26 _ => throw new Exception("I don't like those arguments")
27 };
28}