Esempio n. 1
0
        public void End()
        {
            this.deflateStream.Flush();
            this.deflateStream.Close();
            this.deflateWriter.Close();

            if (!this.useTempStream)
            {
                long curPos = this.BaseStream.Position;
                this.BaseStream.Seek(this.baseStreamPosition, SeekOrigin.Begin);
                uint crc = CheckSum.ComputeHash(this.BaseStream, curPos - this.baseStreamPosition);
                this.BaseStream.Seek(this.baseStreamPosition - 4, SeekOrigin.Begin);
                this.writer.Write(crc);
                this.BaseStream.Seek(curPos, SeekOrigin.Begin);
            }
            else
            {
                this.tempStream.Seek(0, SeekOrigin.Begin);
                uint crc = CheckSum.ComputeHash(this.tempStream, this.tempStream.Length);
                this.writer.Write(crc);
                this.tempStream.Seek(0, SeekOrigin.Begin);
                StreamUtils.CopyStream(this.tempStream, this.BaseStream, (int)this.tempStream.Length);
                this.tempStream.Close();
                this.tempStream = null;
            }
        }
Esempio n. 2
0
            private void CallBack(IAsyncResult ir)
            {
                byte[] buffer = (byte[])ir.AsyncState;
                int    count  = fs.EndRead(ir);

                this.length -= count;
                bool doEnd = this.length <= 0;

                this.evCallBack.WaitOne();
                if (!doEnd)
                {
                    byte[] nextBuffer = buffer == buffer1 ? buffer2 : buffer1;
                    Begin(nextBuffer);
                }
                this.crc = CheckSum.ComputeHash(buffer, 0, count, this.crc);
                this.evCallBack.Set();

                if (doEnd)
                {
                    this.End();
                }
            }