Beispiel #1
0
        public static void CompressorTest(string[] args)
        {
            MemoryDuplex   memory = new MemoryDuplex();
            GzipCompressor c      = new GzipCompressor();

            c.Pipe(memory);
            GzipDecompressor d = new GzipDecompressor();

            memory.Pipe(d);
            d.OnData += (data) => Console.WriteLine("data {0}", data.Stringify());
            c.Write(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
            c.Finish();
            d.Finish();
            Console.ReadKey();
        }
        public void OneThreadDecompressorTest()
        {
            string           archiveFilename  = TestFolder.File("Emgu.gz");
            string           unpackedFilename = "!Emgu.1_thread.chm";
            GzipDecompressor compressor       = new GzipDecompressor();
            int errorType = compressor.ExtractFile(new ArchiveSettings(archiveFilename, unpackedFilename)
            {
                ThreadCount = 1
            });

            Assert.AreEqual(errorType, 0);
            FileInfo fileInfo = new FileInfo(archiveFilename);

            Assert.AreEqual(fileInfo.Length, 11676162);
        }
Beispiel #3
0
        public bool TrySetFor(MessageHead head)
        {
            ThrowIfEnded();
            BodyType?bodyType = BodyType.TryDetectFor(head);

            if (bodyType == null)
            {
                return(false);
            }

            CompressionType  compression = bodyType.Value.CompressionType;
            TransferEncoding transfer    = bodyType.Value.TransferEncoding;
            int contentLength            = bodyType.Value.ContentLength;

            if (IsSet)
            {
                Reset();
            }
            TransferEncoding = transfer;
            if (transfer == TransferEncoding.Raw)
            {
                ContentLength = contentLength;
                State         = BodyParserState.RawRead;
            }
            else if (transfer == TransferEncoding.Chunked)
            {
                State       = BodyParserState.Chunked_Length;
                StringQueue = new StringQueue();
            }
            if (transfer != TransferEncoding.None)
            {
                CompressionType = compression;
                switch (compression)
                {
                case CompressionType.None: ContentTransform = new RawUnifiedDuplex(); break;

                case CompressionType.Gzip: ContentTransform = new GzipDecompressor(); break;

                case CompressionType.Deflate: ContentTransform = new DeflateDecompressor(); break;

                case CompressionType.Compress: return(false);

                default: return(false);
                }
            }
            IsSet = true;
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// Извлечь файл из архива.
        /// </summary>
        /// <param name="archiveFilename">Имя файла архива.</param>
        /// <param name="unpackedFilename">Имя файла для распоковки</param>
        /// <returns>В случае успеха функция возвращает 0, при ошибке  1.</returns>
        public static int ExecuteDecompress(string archiveFilename, string unpackedFilename)
        {
            if (!File.Exists(archiveFilename))
            {
                Console.WriteLine("File not found:" + archiveFilename);
                return(1);
            }


            int errorType;

            using (GzipDecompressor decompressor = new GzipDecompressor())
            {
                errorType = decompressor.ExtractFile(new ArchiveSettings(archiveFilename, unpackedFilename));
            }
            return(errorType);
        }