コード例 #1
0
        /// <summary>
        /// Fills or refills the read buffer.
        /// </summary>
        private void Fill()
        {
            int headerLength = m_targetStream.Read(m_header, 0, HeaderSize);

            // the normal end is here
            if (headerLength == 0)
            {
                m_unpackedBuffer = null;
                return;
            }
            if (headerLength != HeaderSize)
            {
                throw new InvalidDataException("input buffer corrupted (header)");
            }
            int sizeCompressed = Lz4.GetCompressedSize(m_header);

            if (m_readBuffer == null || m_readBuffer.Length < (sizeCompressed + HeaderSize))
            {
                m_readBuffer = new byte[sizeCompressed + HeaderSize];
            }
            Buffer.BlockCopy(m_header, 0, m_readBuffer, 0, HeaderSize);
            int bodyLength = m_targetStream.Read(m_readBuffer, HeaderSize, sizeCompressed);

            if (bodyLength != sizeCompressed)
            {
                throw new InvalidDataException("input buffer corrupted (body)");
            }
            // decompress
            m_unpackedLength = Lz4.Decompress(m_readBuffer, 0, ref m_unpackedBuffer);
            m_unpackedOffset = 0;
        }
コード例 #2
0
 /// <summary>
 /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
 /// </summary>
 /// <exception cref="T:System.IO.IOException">
 /// An I/O error occurs.
 /// </exception>
 public override void Flush()
 {
     if (m_writeBufferOffset > 0)
     {
         int sz = Lz4.Compress(m_writeBuffer, 0, m_writeBufferOffset, ref m_compressedBuffer, m_compressionMode);
         m_targetStream.Write(m_compressedBuffer, 0, sz);
         m_writeBufferOffset = 0;
     }
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZlibCompressionStream" /> class.
 /// </summary>
 /// <param name="targetStream">The target.</param>
 /// <param name="bufferSize">Size of the buffer.</param>
 /// <param name="closeStream">The close stream.</param>
 public Lz4CompressionStream(Stream targetStream, int bufferSize, Lz4Mode mode = Lz4Mode.Fast, bool closeStream = false)
     : this(targetStream, new byte[bufferSize], new byte[Lz4.LZ4_compressBound(bufferSize)], mode, closeStream)
 {
 }