Exemplo n.º 1
0
        public LZ4Decoder(int blockSize, int extraBlocks)
        {
            blockSize   = Mem.RoundUp(Math.Max(blockSize, Mem.K1), Mem.K1);
            extraBlocks = Math.Max(extraBlocks, 0);

            _blockSize    = blockSize;
            _outputLength = Mem.K64 + (1 + extraBlocks) * _blockSize + 8;
            _outputIndex  = 0;
            _outputBuffer = (byte *)Mem.Alloc(_outputLength + 8);
            _context      = (LZ4Context *)Mem.AllocZero(sizeof(LZ4Context));
        }
Exemplo n.º 2
0
 /// <summary>Creates new instance of <see cref="LZ4HighChainEncoder"/></summary>
 /// <param name="level">Compression level.</param>
 /// <param name="blockSize">Block size.</param>
 /// <param name="extraBlocks">Number of extra blocks.</param>
 public LZ4HighChainEncoder(LZ4Level level, int blockSize, int extraBlocks = 0) :
     base(true, blockSize, extraBlocks)
 {
     if (level < LZ4Level.L03_HC)
     {
         level = LZ4Level.L03_HC;
     }
     if (level > LZ4Level.L12_MAX)
     {
         level = LZ4Level.L12_MAX;
     }
     _context = (LZ4Context *)Mem.AllocZero(sizeof(LZ4Context));
     LZ4_64_HC.LZ4_resetStreamHC(_context, (int)level);
 }
Exemplo n.º 3
0
        public uint FastStreamManual(int blockLength, int sourceLength)
        {
            sourceLength = Mem.RoundUp(sourceLength, blockLength);
            var targetLength = 2 * sourceLength;

            var context = (LZ4_xx.LZ4_stream_t *)Mem.AllocZero(sizeof(LZ4_xx.LZ4_stream_t));
            var source  = (byte *)Mem.Alloc(sourceLength);
            var target  = (byte *)Mem.Alloc(targetLength);

            try
            {
                Lorem.Fill(source, sourceLength);

                var sourceP = 0;
                var targetP = 0;

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

                return(Tools.Adler32(target, targetP));
            }
            finally
            {
                Mem.Free(context);
                Mem.Free(source);
                Mem.Free(target);
            }
        }
 public LZ4FastEncoder(int blockSize, int extraBlocks = 0) :
     base(blockSize, extraBlocks)
 {
     _context = (LZ4Context *)Mem.AllocZero(sizeof(LZ4Context));
 }
Exemplo n.º 5
0
 public static LZ4_streamDecode_t *LZ4_createStreamDecode() =>
 (LZ4_streamDecode_t *)Mem.AllocZero(sizeof(LZ4_streamDecode_t));