Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of the <see cref="LZ4HighChainEncoder"/> class.
        /// </summary>
        /// <param name="level">Compression level.</param>
        /// <param name="blockSize">Block size.</param>
        /// <param name="extraBlocks">Number of extra blocks.</param>
        public LZ4HighChainEncoder(LZ4CompressionLevel level, int blockSize, int extraBlocks = 0)
            : base(true, blockSize, extraBlocks)
        {
            if (level < LZ4CompressionLevel.Level3)
            {
                level = LZ4CompressionLevel.Level3;
            }

            if (level > LZ4CompressionLevel.Level12)
            {
                level = LZ4CompressionLevel.Level12;
            }

            _context = (LZ4Context *)LZ4MemoryHelper.AllocZero(sizeof(LZ4Context));
            LZ4Engine64HC.ResetStreamHC(_context, (int)level);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new instance of the <see cref="LZ4FastChainEncoder"/> class.
 /// </summary>
 /// <param name="blockSize">Block size.</param>
 /// <param name="extraBlocks">Number of extra blocks.</param>
 public LZ4FastChainEncoder(int blockSize, int extraBlocks = 0)
     : base(true, blockSize, extraBlocks)
 {
     _context = (LZ4Context *)LZ4MemoryHelper.AllocZero(sizeof(LZ4Context));
 }