コード例 #1
0
        /// <summary>
        /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
        /// </summary>
        /// <param name="buffer">An array of bytes. When this method returns, the buffer contains the specified byte array with the values between <paramref name="offset" /> and (<paramref name="offset" /> + <paramref name="count" /> - 1) replaced by the bytes read from the current source.</param>
        /// <param name="offset">The zero-based byte offset in <paramref name="buffer" /> at which to begin storing the data read from the current stream.</param>
        /// <param name="count">The maximum number of bytes to be read from the current stream.</param>
        /// <returns>
        /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.
        /// </returns>
        public override int Read(byte[] buffer, int offset, int count)
        {
            var ReadCount = InternalDeflateStream.Read(buffer, offset, count);

            if (ReadCount < 1 && CRCData == null)
            {
                CRCData = new byte[4];
                for (int x = 0; x < 4; ++x)
                {
                    CRCData[x] = (byte)InternalStream.ReadByte();
                }
            }
            return(ReadCount);
        }
コード例 #2
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.IO.Stream" /> and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (InternalDeflateStream != null)
                {
                    InternalDeflateStream.Dispose();
                    InternalDeflateStream = null;

                    if (CRCData == null)
                    {
                        CRCData = new byte[4];
                        for (int x = 0; x < 4; ++x)
                        {
                            CRCData[x] = (byte)InternalStream.ReadByte();
                        }
                    }
                }
            }
            base.Dispose(disposing);
        }
コード例 #3
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="T:System.IO.Stream" /> and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (InternalDeflateStream != null)
                {
                    InternalDeflateStream.Dispose();
                    InternalDeflateStream = null;
                }
                else
                {
                    InternalStream.WriteByte(3);
                    InternalStream.WriteByte(0);
                }

                var Crc = (uint)InternalAdler32.Value;
                InternalStream.WriteByte((byte)((Crc >> 24) & 0xFF));
                InternalStream.WriteByte((byte)((Crc >> 16) & 0xFF));
                InternalStream.WriteByte((byte)((Crc >> 8) & 0xFF));
                InternalStream.WriteByte((byte)(Crc & 0xFF));
            }

            base.Dispose(disposing);
        }
コード例 #4
0
 /// <summary>
 /// When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
 /// </summary>
 public override void Flush()
 {
     InternalDeflateStream?.Flush();
 }
コード例 #5
0
 /// <summary>
 /// When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
 /// </summary>
 /// <param name="buffer">An array of bytes. This method copies <paramref name="count" /> bytes from <paramref name="buffer" /> to the current stream.</param>
 /// <param name="offset">The zero-based byte offset in <paramref name="buffer" /> at which to begin copying bytes to the current stream.</param>
 /// <param name="count">The number of bytes to be written to the current stream.</param>
 public override void Write(byte[] buffer, int offset, int count)
 {
     InternalDeflateStream.Write(buffer, offset, count);
     InternalAdler32.Update(buffer, offset, count);
 }