sdbd-demo/SDBD.Demo/Program.cs

29 lines
797 B
C#
Raw Permalink Normal View History

2024-01-09 17:32:46 -05:00
SDBD.ICodec codec = new SDBD.Codec();
2024-01-09 21:51:31 -05:00
var (encode, filepath) = ParseArgs(args);
var inputData = File.ReadAllBytes(filepath);
var filename = Path.GetFileName(filepath);
2024-01-09 17:32:46 -05:00
if(encode) {
SDBD.Document document = new (
new() {
{ "content-name", filename }
},
inputData
);
var outputData = codec.Encode(document);
2024-01-09 20:33:32 -05:00
File.WriteAllBytes($"{filename}.sdbd", outputData);
2024-01-09 17:32:46 -05:00
} else {
var document = codec.Decode(inputData);
File.WriteAllBytes(document.Metadata["content-name"], document.Data);
}
2024-01-09 21:51:31 -05:00
(bool encode, string filepath) ParseArgs(string[] args) {
2024-01-09 17:32:46 -05:00
return args switch {
2024-01-09 21:51:31 -05:00
[var filepath] => (true, filepath),
["-d", var filepath] => (false, filepath),
["-e", var filepath] => (true, filepath),
2024-01-09 17:32:46 -05:00
_ => throw new Exception("I don't like those arguments")
};
2024-01-09 17:46:34 -05:00
}