Example #1
0
        public void Analyze(string path)
        {
            var fileReader = new FileReader();
            var fileWriter = new FileWriter();

            var encodedFile = fileReader.ReadEncoded(path);
            var pipeline    = default(IPipelineRunner);

            if (encodedFile.Header.Pipeline == AlgorithmPipeline.RLE_Huffman)
            {
                pipeline = new RLE_HuffmanPipeline();
            }
            else if (encodedFile.Header.Pipeline == AlgorithmPipeline.LZW_Huffman)
            {
                pipeline = new LZW_HuffmanPipeline();
            }
            else
            {
                throw new InvalidOperationException("Pipeline does not exists");
            }

            var index      = path.LastIndexOf('.');
            var outPutPath = path.Remove(index, path.Length - index);
            var source     = pipeline.Run(encodedFile, outPutPath);

            fileWriter.WriteSource(source);
        }
Example #2
0
        public void Analyze(string path)
        {
            var reader = new FileReader();
            var writer = new FileWriter();

            var source = reader.ReadSource(path);

            var rleAnalyzer  = new RLEAnalyzer();
            var shouldUseRle = rleAnalyzer.Analyze(source);

            var encoded  = default(EncodedFile);
            var pipeline = default(IPipelineRunner);

            if (shouldUseRle)
            {
                pipeline = new RLE_HuffmanPipeline();
            }
            else
            {
                pipeline = new LZW_HuffmanPipeline();
            }

            try
            {
                encoded = pipeline.Run(source);
            }
            catch (RleException)
            {
                pipeline = new LZW_HuffmanPipeline();
                encoded  = pipeline.Run(source);
            }

            encoded.SetPath(path);

            writer.WriteEncoded(encoded);
        }