Exemplo n.º 1
0
        public void BZ_Samples()
        {
            string testBin           = GetTestBinDir(CurrentDir);
            string resourceDir       = Path.Combine(testBin, "Resources");
            var    filesToDecompress = Directory.GetFiles(resourceDir, "*.bz2");

            Assert.IsTrue(filesToDecompress.Length > 2,
                          "There are not enough sample files");

            foreach (var filename in filesToDecompress)
            {
                TestContext.WriteLine("Decompressing {0}", filename);
                var outFname = filename + ".decompressed";
                TestContext.WriteLine("Decompressing to {0}", outFname);

                using (var fs = File.OpenRead(filename))
                {
                    using (var output = File.Create(outFname))
                    {
                        using (var decompressor = new Ionic.BZip2.BZip2InputStream(fs))
                        {
                            CopyStream(decompressor, output);
                        }
                    }
                }
                TestContext.WriteLine("");
            }
        }
Exemplo n.º 2
0
 // Token: 0x060006DF RID: 1759 RVA: 0x0003D438 File Offset: 0x0003B638
 private void createHuffmanDecodingTables(int alphaSize, int nGroups)
 {
     BZip2InputStream.DecompressionState decompressionState = this.data;
     char[][] temp_charArray2d = decompressionState.temp_charArray2d;
     for (int i = 0; i < nGroups; i++)
     {
         int    num   = 32;
         int    num2  = 0;
         char[] array = temp_charArray2d[i];
         int    num3  = alphaSize;
         while (--num3 >= 0)
         {
             char c = array[num3];
             if ((int)c > num2)
             {
                 num2 = (int)c;
             }
             if ((int)c < num)
             {
                 num = (int)c;
             }
         }
         BZip2InputStream.hbCreateDecodeTables(decompressionState.gLimit[i], decompressionState.gBase[i], decompressionState.gPerm[i], temp_charArray2d[i], num, num2, alphaSize);
         decompressionState.gMinlen[i] = num;
     }
 }
Exemplo n.º 3
0
        public void BZ_Error_2()
        {
            string decompressedFname = "ThisWillNotWork.txt";

            using (Stream input = new MemoryStream(), // empty stream
                   decompressor = new Ionic.BZip2.BZip2InputStream(input),
                   output = File.Create(decompressedFname))
                CopyStream(decompressor, output);
        }
Exemplo n.º 4
0
        public void BZ_Error_1()
        {
            var    bzbin             = GetToolsBinDir(CurrentDir);
            var    dnzBzip2exe       = Path.Combine(bzbin, "bzip2.exe");
            string decompressedFname = "ThisWillNotWork.txt";

            using (Stream input = File.OpenRead(dnzBzip2exe),
                   decompressor = new Ionic.BZip2.BZip2InputStream(input),
                   output = File.Create(decompressedFname))
                CopyStream(decompressor, output);
        }
Exemplo n.º 5
0
        public static string Decompress(string fname, bool forceOverwrite)
        {
            var outFname = Path.GetFileNameWithoutExtension(fname);

            if (File.Exists(outFname))
            {
                if (forceOverwrite)
                {
                    File.Delete(outFname);
                }
                else
                {
                    return(null);
                }
            }

            using (Stream fs = File.OpenRead(fname),
                   output = File.Create(outFname),
                   decompressor = new Ionic.BZip2.BZip2InputStream(fs))
                Pump(decompressor, output);

            return(outFname);
        }
Exemplo n.º 6
0
        public void BZ_Samples()
        {
            string testBin = GetTestBinDir(CurrentDir);
            string resourceDir = Path.Combine(testBin, "Resources");
            var filesToDecompress = Directory.GetFiles(resourceDir, "*.bz2");

            Assert.IsTrue(filesToDecompress.Length > 2,
                          "There are not enough sample files");

            foreach (var filename in filesToDecompress)
            {
                TestContext.WriteLine("Decompressing {0}", filename);
                var outFname = filename + ".decompressed";
                TestContext.WriteLine("Decompressing to {0}", outFname);

                using (var fs = File.OpenRead(filename))
                {
                    using (var output = File.Create(outFname))
                    {
                        using (var decompressor = new Ionic.BZip2.BZip2InputStream(fs))
                        {
                            CopyStream(decompressor, output);
                        }
                    }
                }
                TestContext.WriteLine("");
            }
        }
Exemplo n.º 7
0
 public void BZ_Error_2()
 {
     string decompressedFname = "ThisWillNotWork.txt";
     using (Stream input = new MemoryStream(), // empty stream
            decompressor = new Ionic.BZip2.BZip2InputStream(input),
            output = File.Create(decompressedFname))
         CopyStream(decompressor, output);
 }
Exemplo n.º 8
0
 public void BZ_Error_1()
 {
     var bzbin = GetTestDependentDir(CurrentDir, "Tools\\BZip2\\bin\\Debug");
     var dnzBzip2exe = Path.Combine(bzbin, "bzip2.exe");
     string decompressedFname = "ThisWillNotWork.txt";
     using (Stream input = File.OpenRead(dnzBzip2exe),
            decompressor = new Ionic.BZip2.BZip2InputStream(input),
            output = File.Create(decompressedFname))
         CopyStream(decompressor, output);
 }
Exemplo n.º 9
0
        [Timeout(15 * 60*1000)] // 60*1000 = 1min
        public void BZ_Basic()
        {
            TestContext.WriteLine("Creating fodder file.");
            // select a random text string
            var line = TestStrings.ElementAt(this.rnd.Next(0, TestStrings.Count)).Value;
            int n = 4000 + this.rnd.Next(1000); // number of iters
            var fname = "Pippo.txt";
            // emit many many lines into a text file:
            using (var sw = new StreamWriter(File.Create(fname)))
            {
                for (int k=0; k < n; k++)
                {
                    sw.WriteLine(line);
                }
            }
            int crcOriginal = GetCrc(fname);
            int blockSize = 0;

            Func<Stream,Stream>[] getBzStream = {
                new Func<Stream,Stream>( s0 => {
                        var decorator = new Ionic.BZip2.BZip2OutputStream(s0, blockSize);
                        return decorator;
                    }),
                new Func<Stream,Stream>( s1 => {
                        var decorator = new Ionic.BZip2.ParallelBZip2OutputStream(s1, blockSize);
                        return decorator;
                    })
            };

            int[] blockSizes = { 1,2,3,4,5,6,7,8,9 };

            for (int k=0; k < getBzStream.Length; k++)
            {
                for (int m=0; m < blockSizes.Length; m++)
                {
                    blockSize = blockSizes[m];
                    var getStream = getBzStream[k];
                    var root = Path.GetFileNameWithoutExtension(fname);
                    var ext = Path.GetExtension(fname);
                    // compress into bz2
                    var bzFname = String.Format("{0}.{1}.blocksize{2}{3}.bz2",
                                                root,
                                                (k==0)?"SingleThread":"MultiThread",
                                                blockSize, ext);

                    TestContext.WriteLine("Compress cycle ({0},{1})", k,m);
                    TestContext.WriteLine("file {0}", bzFname);
                    using (var fs = File.OpenRead(fname))
                    {
                        using (var output = File.Create(bzFname))
                        {
                            using (var compressor = getStream(output))
                            {
                                CopyStream(fs, compressor);
                            }
                        }
                    }

                    TestContext.WriteLine("Decompress");
                    var decompressedFname = Path.GetFileNameWithoutExtension(bzFname);
                    using (Stream fs = File.OpenRead(bzFname),
                           output = File.Create(decompressedFname),
                           decompressor = new Ionic.BZip2.BZip2InputStream(fs))
                    {
                        CopyStream(decompressor, output);
                    }

                    TestContext.WriteLine("Check CRC");
                    int crcDecompressed = GetCrc(decompressedFname);
                    Assert.AreEqual<int>(crcOriginal, crcDecompressed,
                                         "CRC mismatch {0:X8} != {1:X8}",
                                         crcOriginal, crcDecompressed);
                    TestContext.WriteLine("");

                    // just for the sake of disk space economy:
                    File.Delete(decompressedFname);
                    File.Delete(bzFname);
                }
            }
        }
Exemplo n.º 10
0
        [Timeout(15 * 60 * 1000)] // 60*1000 = 1min
        public void BZ_Basic()
        {
            TestContext.WriteLine("Creating fodder file.");
            // select a random text string
            var line  = TestStrings.ElementAt(this.rnd.Next(0, TestStrings.Count)).Value;
            int n     = 4000 + this.rnd.Next(1000); // number of iters
            var fname = "Pippo.txt";

            // emit many many lines into a text file:
            using (var sw = new StreamWriter(File.Create(fname)))
            {
                for (int k = 0; k < n; k++)
                {
                    sw.WriteLine(line);
                }
            }
            int crcOriginal = GetCrc(fname);
            int blockSize   = 0;

            Func <Stream, Stream>[] getBzStream =
            {
                new Func <Stream, Stream>(s0 => {
                    var decorator = new Ionic.BZip2.BZip2OutputStream(s0,blockSize);
                    return(decorator);
                }),
                new Func <Stream, Stream>(s1 => {
                    var decorator = new Ionic.BZip2.ParallelBZip2OutputStream(s1,blockSize);
                    return(decorator);
                })
            };

            int[] blockSizes = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            for (int k = 0; k < getBzStream.Length; k++)
            {
                for (int m = 0; m < blockSizes.Length; m++)
                {
                    blockSize = blockSizes[m];
                    var getStream = getBzStream[k];
                    var root      = Path.GetFileNameWithoutExtension(fname);
                    var ext       = Path.GetExtension(fname);
                    // compress into bz2
                    var bzFname = String.Format("{0}.{1}.blocksize{2}{3}.bz2",
                                                root,
                                                (k == 0)?"SingleThread":"MultiThread",
                                                blockSize, ext);

                    TestContext.WriteLine("Compress cycle ({0},{1})", k, m);
                    TestContext.WriteLine("file {0}", bzFname);
                    using (var fs = File.OpenRead(fname))
                    {
                        using (var output = File.Create(bzFname))
                        {
                            using (var compressor = getStream(output))
                            {
                                CopyStream(fs, compressor);
                            }
                        }
                    }

                    TestContext.WriteLine("Decompress");
                    var decompressedFname = Path.GetFileNameWithoutExtension(bzFname);
                    using (Stream fs = File.OpenRead(bzFname),
                           output = File.Create(decompressedFname),
                           decompressor = new Ionic.BZip2.BZip2InputStream(fs))
                    {
                        CopyStream(decompressor, output);
                    }

                    TestContext.WriteLine("Check CRC");
                    int crcDecompressed = GetCrc(decompressedFname);
                    Assert.AreEqual <int>(crcOriginal, crcDecompressed,
                                          "CRC mismatch {0:X8} != {1:X8}",
                                          crcOriginal, crcDecompressed);
                    TestContext.WriteLine("");

                    // just for the sake of disk space economy:
                    File.Delete(decompressedFname);
                    File.Delete(bzFname);
                }
            }
        }
Exemplo n.º 11
0
        public static string Decompress(string fname, bool forceOverwrite)
        {
            var outFname = Path.GetFileNameWithoutExtension(fname);
            if (File.Exists(outFname))
            {
                if (forceOverwrite)
                    File.Delete(outFname);
                else
                    return null;
            }

            using (Stream fs = File.OpenRead(fname),
                   output = File.Create(outFname),
                   decompressor = new Ionic.BZip2.BZip2InputStream(fs))
                Pump(decompressor, output);

            return outFname;
        }