Example #1
0
        public static CompressAlgorithmBlocks Init(string inputFilePath, string outputFilePath)
        {
            var blocks = new CompressAlgorithmBlocks();

            try
            {
                blocks.inputFileStream     = File.OpenRead(inputFilePath);
                blocks.inputBufferedStream = new BufferedStream(blocks.inputFileStream);
                blocks.binaryReader        = new BinaryReader(blocks.inputBufferedStream);
            } catch (FileNotFoundException e)
            {
                Console.WriteLine($"Unable to find on the path: {inputFilePath}");
                throw new HandledException(e);
            }
            try
            {
                blocks.outputFileStream     = File.Open(outputFilePath, FileMode.Create);
                blocks.outputBufferedStream = new BufferedStream(blocks.outputFileStream);
                blocks.binaryWriter         = new BinaryWriter(blocks.outputBufferedStream);
            } catch (FileNotFoundException e)
            {
                Console.WriteLine($"Unable to create file on the path: {outputFilePath}");
                throw new HandledException(e);
            }
            return(blocks);
        }
Example #2
0
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.WriteLine("Invalid Syntax, use the following one 'archiver compress|decompress <inputFile> <outputFile>'");
                return(1);
            }
            bool compress = false;

            if (string.Compare(args[0], "compress", true) == 0)
            {
                compress = true;
            }
            else if (string.Compare(args[0], "decompress", true) == 0)
            {
                compress = false;
            }
            else
            {
                Console.WriteLine($"Expected 'compress' or 'decompress' command, but found '{args[0]}'");
                return(1);
            }
            try
            {
                using (var blocks =
                           compress
                    ? (AlgorithmBlocks)CompressAlgorithmBlocks.Init(args[1], args[2])
                    : (AlgorithmBlocks)DecompressAlgorithmBlocks.Init(args[1], args[2])
                       )
                {
                    var algorithm = new ParallelAlgorithm <byte[], byte[]>(blocks.GetBlock, blocks.ProcessBlock, blocks.UseResult);
                    return(algorithm.Run());
                }
            } catch (HandledException e)
            {
                return(1);
            } catch (Exception e)
            {
                Console.WriteLine($"Unhandled exception: {e.Message}");
                return(1);
            }
        }