Example #1
0
        static void Main(string[] args)
        {
            LogHelper.Setup();

            // encode -i Base64Tool.deps.json -o test.out
            // decode -i test.out -o test.decoded.txt --decode

            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(o =>
            {
                string inputFile      = o.InputFile;
                string outputFilePath = o.OutputFilePath;

                if (!File.Exists(inputFile))
                {
                    log.ErrorFormat($@"Cannot open input file ""{inputFile}""");
                    Environment.Exit(-1);
                }

                bool displayProgress = !Console.IsInputRedirected || !Console.IsOutputRedirected;

                Base64Helper base64Helper = new Base64Helper(displayProgress);

                if (o.Decode)
                {
                    if (!base64Helper.DecodeFromBase64(inputFile, outputFilePath, out long processedBytes, out long readBytes))
                    {
                        log.ErrorFormat($@"Cannot write to file ""{outputFilePath}""");
                        Environment.Exit(-1);
                    }
                    else
                    {
                        log.InfoFormat($@"Decoded {readBytes} bytes. Wrote {processedBytes} bytes");
                        Environment.Exit(0);
                    }
                }