Esempio n. 1
0
 /// <summary>
 /// Creates new instance of the <see cref="LZ4BlockDecoder"/> class.
 /// </summary>
 /// <param name="blockSize">Block size. Must be equal or greater to one used for compression.</param>
 public LZ4BlockDecoder(int blockSize)
 {
     blockSize     = LZ4MemoryHelper.RoundUp(Math.Max(blockSize, LZ4MemoryHelper.K1), LZ4MemoryHelper.K1);
     _blockSize    = blockSize;
     _outputLength = _blockSize + 8;
     _outputIndex  = 0;
     _outputBuffer = (byte *)LZ4MemoryHelper.Alloc(_outputLength + 8);
 }
Esempio n. 2
0
        /// <summary>
        /// Creates a new instance of the <see cref="LZ4Encoder"/> class.
        /// </summary>
        /// <param name="chaining">Needs to be `true` if using dependent blocks.</param>
        /// <param name="blockSize">Block size.</param>
        /// <param name="extraBlocks">Number of extra blocks.</param>
        protected LZ4Encoder(bool chaining, int blockSize, int extraBlocks)
        {
            blockSize   = LZ4MemoryHelper.RoundUp(Math.Max(blockSize, LZ4MemoryHelper.K1), LZ4MemoryHelper.K1);
            extraBlocks = Math.Max(extraBlocks, 0);
            int dictSize = chaining ? LZ4MemoryHelper.K64 : 0;

            _blockSize   = blockSize;
            _inputLength = dictSize + (1 + extraBlocks) * blockSize + 8;
            _inputIndex  = _inputPointer = 0;
            _inputBuffer = (byte *)LZ4MemoryHelper.Alloc(_inputLength + 8);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates new instance of the <see cref="LZ4ChainDecoder"/> class.
        /// </summary>
        /// <param name="blockSize">Block size.</param>
        /// <param name="extraBlocks">Number of extra blocks.</param>
        public LZ4ChainDecoder(int blockSize, int extraBlocks)
        {
            blockSize   = LZ4MemoryHelper.RoundUp(Math.Max(blockSize, LZ4MemoryHelper.K1), LZ4MemoryHelper.K1);
            extraBlocks = Math.Max(extraBlocks, 0);

            _blockSize    = blockSize;
            _outputLength = LZ4MemoryHelper.K64 + (1 + extraBlocks) * _blockSize + 8;
            _outputIndex  = 0;
            _outputBuffer = (byte *)LZ4MemoryHelper.Alloc(_outputLength + 8);
            _context      = (LZ4Context *)LZ4MemoryHelper.AllocZero(sizeof(LZ4Context));
        }
Esempio n. 4
0
        public uint FastStreamManual(int blockLength, int sourceLength)
        {
            sourceLength = LZ4MemoryHelper.RoundUp(sourceLength, blockLength);
            var targetLength = 2 * sourceLength;

            var context = (LZ4Engine.StreamT *)LZ4MemoryHelper.AllocZero(sizeof(LZ4Engine.StreamT));
            var source  = (byte *)LZ4MemoryHelper.Alloc(sourceLength);
            var target  = (byte *)LZ4MemoryHelper.Alloc(targetLength);

            try
            {
                Lorem.Fill(source, sourceLength);

                var sourceP = 0;
                var targetP = 0;

                while (sourceP < sourceLength && targetP < targetLength)
                {
                    targetP += LZ4Engine64.CompressFastContinue(
                        context,
                        source + sourceP,
                        target + targetP,
                        Math.Min(blockLength, sourceLength - sourceP),
                        targetLength - targetP,
                        1);
                    sourceP += blockLength;
                }

                return(Tools.Adler32(target, targetP));
            }
            finally
            {
                LZ4MemoryHelper.Free(context);
                LZ4MemoryHelper.Free(source);
                LZ4MemoryHelper.Free(target);
            }
        }