コード例 #1
0
ファイル: ZlibOutputStream.cs プロジェクト: Chapmania/Juniper
        private void DoInit()
        {
            if (initdone)
            {
                return;
            }

            initdone = true;
            // http://stackoverflow.com/a/2331025/277304
            const int cmf = 0x78;
            var       flg = 218; // sorry about the following lines

            if (CompressLevel >= 5 && CompressLevel <= 6)
            {
                flg = 156;
            }
            else if (CompressLevel >= 3 && CompressLevel <= 4)
            {
                flg = 94;
            }
            else if (CompressLevel <= 2)
            {
                flg = 1;
            }

            flg -= (((cmf * 256) + flg) % 31); // just in case
            if (flg < 0)
            {
                flg += 31;
            }

            RawStream.WriteByte(cmf);
            RawStream.WriteByte((byte)flg);
        }
コード例 #2
0
 public override void WriteByte(byte value)
 {
     if (m_IsCompressed)
     {
         m_Buffer.WriteByte(value);
         if (m_Buffer.Position >= m_BlockSize)
         {
             FlushBuffer();
         }
     }
     else
     {
         RawStream.WriteByte(value);
     }
 }
コード例 #3
0
ファイル: ZlibOutputStream.cs プロジェクト: Chapmania/Juniper
        public override void Close()
        {
            if (!initdone)
            {
                DoInit(); // can happen if never called write
            }

            if (closed)
            {
                return;
            }

            closed = true;
            // sigh ... no only must I close the parent stream to force a flush, but I must save a reference
            // raw stream because (apparently) Close() sets it to null (shame on you, MS developers)
            if (deflateStream is object)
            {
                deflateStream.Close();
            }
            else
            {         // second hack: empty input?
                RawStream.WriteByte(3);
                RawStream.WriteByte(0);
            }
            // add crc
            var crcv = adler32.GetValue();

            RawStream.WriteByte((byte)((crcv >> 24) & 0xFF));
            RawStream.WriteByte((byte)((crcv >> 16) & 0xFF));
            RawStream.WriteByte((byte)((crcv >> 8) & 0xFF));
            RawStream.WriteByte((byte)(crcv & 0xFF));
            if (!LeaveOpen)
            {
                RawStream.Close();
            }
        }