Exemplo n.º 1
0
        private void Fill()
        {
            int num = _targetStream.Read(_header, 0, HeaderSize);

            if (num == 0)
            {
                _unpackedBuffer = null;
            }
            else
            {
                if (num != 8)
                {
                    throw new InvalidDataException("input buffer corrupted (header)");
                }
                int compressedSize = Lz4.GetCompressedSize(_header);
                if ((_readBuffer == null) || (_readBuffer.Length < (compressedSize + HeaderSize)))
                {
                    _readBuffer = new byte[compressedSize + HeaderSize];
                }
                Buffer.BlockCopy(_header, 0, _readBuffer, 0, HeaderSize);
                if (_targetStream.Read(_readBuffer, HeaderSize, compressedSize) != compressedSize)
                {
                    throw new InvalidDataException("input buffer corrupted (body)");
                }
                _unpackedLength = Lz4.Decompress(_readBuffer, 0, ref _unpackedBuffer);
                _unpackedOffset = 0;
            }
        }
Exemplo n.º 2
0
        public override void Flush()
        {
            if (_writeBufferOffset <= 0)
            {
                return;
            }
            var count = Lz4.Compress(_writeBuffer, 0, _writeBufferOffset, ref _compressedBuffer, _compressionMode);

            _targetStream.Write(_compressedBuffer, 0, count);
            _writeBufferOffset = 0;
        }
Exemplo n.º 3
0
 public Lz4CompressionStream(Stream targetStream, int bufferSize, Lz4Mode mode = 0, bool closeStream = false)
     : this(targetStream, new byte[bufferSize], new byte[Lz4.LZ4_compressBound(bufferSize)], mode, closeStream)
 {
 }