コード例 #1
0
        private void Initialize(DeflateSettings deflateSettings)
        {
            this.compressionLevel = (int)deflateSettings.CompressionLevel;
            this.windowBits       = 15;
            int num = 8;

            this.windowSize      = 1 << this.windowBits;
            this.windowMask      = this.windowSize - 1;
            this.hashBits        = num + 7;
            this.hashSize        = 1 << this.hashBits;
            this.hashMask        = this.hashSize - 1;
            this.hashShift       = (this.hashBits + 3 - 1) / 3;
            this.window          = new byte[this.windowSize * 2];
            this.previous        = new short[this.windowSize];
            this.head            = new short[this.hashSize];
            this.literalsBufsize = 1 << num + 6;
            this.pending         = new byte[this.literalsBufsize * 4];
            this.distanceOffset  = this.literalsBufsize;
            this.lengthOffset    = 3 * this.literalsBufsize;
            this.TotalBytesIn    = this.TotalBytesOut = 0;
            this.pendingCount    = 0;
            this.nextPending     = 0;
            this.InitializeTreeData();
            this.InitializeLazyMatch();
        }
コード例 #2
0
        private void SaveEntry(
            FileStream stream,
            string fileName,
            string fileNameInZip,
            DateTime dateTime)
        {
            FileInfo fileInfo   = new FileInfo(fileName);
            int      attributes = (int)fileInfo.Attributes;

            this.DeleteAvailableEntry(fileNameInZip);
            string          entryName       = fileNameInZip;
            DeflateSettings deflateSettings = new DeflateSettings()
            {
                CompressionLevel = CompressionLevel.Optimal, HeaderType = CompressedStreamHeader.None
            };

            using (ZipArchiveEntry entry = this.CreateEntry(entryName, (CompressionSettings)deflateSettings))
            {
                Stream stream1 = entry.Open();
                if (stream != null)
                {
                    byte[] buffer = new byte[4096];
                    int    count;
                    while ((count = stream.Read(buffer, 0, buffer.Length)) != 0)
                    {
                        stream1.Write(buffer, 0, count);
                    }
                }
                entry.LastWriteTime      = (DateTimeOffset)fileInfo.LastWriteTime;
                entry.ExternalAttributes = attributes;
            }
        }
コード例 #3
0
 public void Initialize(CompressionSettings settings)
 {
     this.deflateSettings = settings as DeflateSettings;
     if (this.deflateSettings == null)
     {
         throw new ArgumentException("Wrong settings type.");
     }
 }
コード例 #4
0
 public DeflateDecompressor(DeflateSettings settings)
     : base(settings)
 {
     this.output   = new OutputWindow();
     this.input    = new InputBitsBuffer();
     this.codeList = new byte[320];
     this.codeLengthTreeCodeLength = new byte[19];
     this.Reset();
 }
コード例 #5
0
        public DeflateCompressor(DeflateSettings settings)
            : base(settings)
        {
            int length = 573;

            this.dynamicLiteralsTree  = new short[length * 2];
            this.dynamicDistanceTree  = new short[122];
            this.dynamicBitLengthTree = new short[78];
            this.BitLengthCount       = new short[16];
            this.Heap  = new int[length];
            this.Depth = new sbyte[length];
            this.Initialize(settings);
        }
コード例 #6
0
        public void AddStream(
            Stream stream,
            string fileNameInZip,
            ZipCompression method,
            DateTime dateTime,
            CompressionType compressionType)
        {
            if (compressionType == CompressionType.Lzma)
            {
                throw new NotSupportedException();
            }
            DeflateSettings deflateSettings = ZipOutputStream.CreateDeflateSettings(method);

            deflateSettings.HeaderType = CompressedStreamHeader.None;
            this.DeleteAvailableEntry(fileNameInZip);
            using (ZipArchiveEntry entry = this.CreateEntry(fileNameInZip, (CompressionSettings)deflateSettings))
            {
                entry.LastWriteTime      = (DateTimeOffset)dateTime;
                entry.ExternalAttributes = 32;
                Stream destination = entry.Open();
                ZipFile.CopyStreamTo(stream, destination);
            }
        }