public void Decompress_Test()
        {
            string hash;
            byte[] archivedFile;
            long bufferSize = 20 * 1024 * 1024;

            using (MD5 md5Hash = MD5.Create())
            {
                hash = Helper.GetMd5Hash(md5Hash, file);
            }

            var engine = new CompressEngine(new GZipCompress(), 100);
            using (MemoryStream original = new MemoryStream(file))
            {
                using (MemoryStream archive = new MemoryStream())
                {
                    engine.DoAction(original, archive, bufferSize);
                    archivedFile = archive.ToArray();
                }
            }

            GZipDecompress gzip = new GZipDecompress();
            var originalFile = gzip.DoWork(archivedFile);

            using (MD5 md5Hash = MD5.Create())
            {
                hash = Helper.GetMd5Hash(md5Hash, originalFile);

                Assert.IsTrue(Helper.VerifyMd5Hash(md5Hash, file, hash));
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            int capaticy = 50;

            AppDomain.CurrentDomain.UnhandledException += ExceptionHandler;

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                Console.WriteLine();
                _isCancelled = true;
                if (_backgroundThread != null)
                    _backgroundThread.Abort();
            };

            if (ValidateArguments(args))
            {
                bool compress = string.Equals(args[0], COMPRESS);
                string initPath = args[1];
                string archPath = args[2];

                IArchivator compressor = new CompressEngine(new GZipCompress(), capaticy);
                IArchivator decompressor = new DecompressEngine(new GZipDecompress(), capaticy);

                _ss = new Thread(() => ScreenSaver()) { IsBackground = true, Name = "ScreenSaver" };

                Console.WriteLine("Operation Started");
                _ss.Start();

                if (string.Equals(args[0], COMPRESS))
                {
                    _backgroundThread = new Thread(() => Compress(initPath, archPath, compressor, ARCHIVE_SIZE)) { IsBackground = true, Name = "MainProgram" };
                    _backgroundThread.Start();
                }
                else if (string.Equals(args[0], DECOMPRESS))
                {
                    _backgroundThread = new Thread(() => DeCompress(initPath, archPath, decompressor, ARCHIVE_SIZE)) { IsBackground = true };
                    _backgroundThread.Start();
                }

                _mainEvent.WaitOne();

                Console.WriteLine();

                if (_isCompleted)
                    Console.WriteLine("0");
                else if (_isCancelled)
                    Console.WriteLine("Cancelled");
                else if (_isError)
                    Console.WriteLine("1");

                Console.WriteLine();
                Console.WriteLine("Press any key");
                Console.ReadLine();
            }
        }
        public void Compress_Test_CAPACITY_TOTAL_SEGMENTS_5_20()
        {
            long bufferSize = 1 * 1024 * 1024;
            int capacity = 5;

            byte[] archivedFile;

            var engine = new CompressEngine(new GZipCompress(), capacity);
            using (MemoryStream original = new MemoryStream(file))
            {
                using (MemoryStream archive = new MemoryStream())
                {
                    engine.DoAction(original, archive, bufferSize);
                    archivedFile = archive.ToArray();
                }
            }
        }
        private void CompressDeCompress(long bufferSize)
        {
            byte[] archivedFile;

            string hash;

            using (MD5 md5Hash = MD5.Create())
            {
                hash = Helper.GetMd5Hash(md5Hash, file);
            }

            var engine = new CompressEngine(new GZipCompress(), capacity);
            using (MemoryStream original = new MemoryStream(file))
            {
                using (MemoryStream archive = new MemoryStream())
                {
                    engine.DoAction(original, archive, bufferSize);
                    archivedFile = archive.ToArray();
                }
            }

            byte[] dearchivedFile = null;
            using (MemoryStream archive = new MemoryStream(archivedFile))
            {
                using (MemoryStream original = new MemoryStream())
                {
                    DecompressEngine engine2 = new DecompressEngine(new GZipDecompress(), capacity);
                    engine2.DoAction(archive, original, bufferSize);
                    dearchivedFile = original.ToArray();
                }
            }

            using (MD5 md5Hash = MD5.Create())
            {
                Assert.IsTrue(Helper.VerifyMd5Hash(md5Hash, dearchivedFile, hash));
            }
        }