示例#1
0
        public void TestGzipParsingWithSpaces()
        {
            var list = StrategyConfigParser.ParseConfig("   gzip    ").ToList();

            Assert.AreEqual(1, list.Count);
            Assert.IsInstanceOf <GZipCompressionStrategy>(list[0]);
        }
示例#2
0
        public void TestMultiGzipParsing()
        {
            var list = StrategyConfigParser.ParseConfig("gzip;gzip").ToList();

            Assert.AreEqual(2, list.Count);
            Assert.IsInstanceOf <GZipCompressionStrategy>(list[0]);
            Assert.IsInstanceOf <GZipCompressionStrategy>(list[1]);
        }
示例#3
0
        public void TestArithmeticParsing()
        {
            var list = StrategyConfigParser.ParseConfig("arithm,456").ToList();

            Assert.AreEqual(1, list.Count);
            Assert.IsInstanceOf <ArithmeticCodingStrategy>(list[0]);
            Assert.AreEqual(456, ((ArithmeticCodingStrategy)list[0]).InnerChunkSize);
        }
示例#4
0
        public void TestExternalParsing()
        {
            var list = StrategyConfigParser.ParseConfig("ext,gzip -,gunzip -").ToList();

            Assert.AreEqual(1, list.Count);
            Assert.IsInstanceOf <ExternalCompressionStrategy>(list[0]);

            var strategy = (ExternalCompressionStrategy)list[0];

            Assert.AreEqual("gzip -", strategy.Config.CompressCommand);
            Assert.AreEqual("gunzip -", strategy.Config.UncompressCommand);
        }
示例#5
0
        public static void Main(string[] args)
        {
            var brutePackMain = new BrutePackMain();

            if (!Parser.Default.ParseArguments(args, brutePackMain))
            {
                return;
            }
            var inputFile  = brutePackMain.InputFile;
            var outputFile = brutePackMain.OutputFile;
            var decompress = brutePackMain.Decompress;

            if (outputFile == "")
            {
                GenerateOutputFilename(inputFile, decompress, out outputFile);
            }

            if (!decompress)
            {
                if (brutePackMain.ConfigFile.NullOrEmpty() && brutePackMain.ConfigString.NullOrEmpty())
                {
                    Console.WriteLine("You must specify -c or -f for compression");
                    return;
                }
            }

            var inputStream  = new FileStream(inputFile, FileMode.Open);
            var outputStream = new FileStream(outputFile, FileMode.CreateNew);


            if (decompress)
            {
                using (var uncompressStream = new BruteUncompressingStream(new BinaryReader(inputStream)))
                    uncompressStream.CopyTo(outputStream);
                outputStream.Flush();
                outputStream.Close();
            }
            else
            {
                var configString = brutePackMain.ConfigFile.NullOrEmpty()
                    ? brutePackMain.ConfigString
                    : File.ReadAllText(brutePackMain.ConfigFile);
                var parsedConfig =
                    StrategyConfigParser.ParseConfig(configString)
                    .Concat(Enumerable.Repeat <ICompressionStrategy>(new DumbCompressionStrategy(), 1));
                var compressingStream = new BruteCompressingStream(new BinaryWriter(outputStream),
                                                                   brutePackMain.MaxBufferSize, new BruteCompressionStrategy(parsedConfig));
                inputStream.CopyTo(compressingStream);
                compressingStream.Flush();
                compressingStream.Close();
            }
        }
示例#6
0
 public void TestMultiEmptyNestedPatterns()
 {
     Assert.AreEqual(0, StrategyConfigParser.ParseConfig(",;,").ToList().Count);
 }
示例#7
0
 public void TestEmptyPatterns()
 {
     Assert.AreEqual(0, StrategyConfigParser.ParseConfig("").ToList().Count);
 }
示例#8
0
 public void TestFaultyParsing()
 {
     var list = StrategyConfigParser.ParseConfig("top kek").ToList();
 }