Пример #1
0
        public static unsafe int Encode(byte *source, int sourceLength, byte *target, int targetLength, LZ4CompressionLevel level = LZ4CompressionLevel.Level0)
        {
            if (sourceLength <= 0)
            {
                return(0);
            }

            int encoded = level == LZ4CompressionLevel.Level0
                                ? LZ4Engine64.CompressDefault(source, target, sourceLength, targetLength)
                                : LZ4Engine64HC.CompressHC(source, target, sourceLength, targetLength, (int)level);

            return(encoded <= 0 ? -1 : encoded);
        }
Пример #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);
        }
Пример #3
0
 /// <see cref="LZ4Encoder.CopyDict(byte*, int)"/>
 protected override int CopyDict(byte *target, int length)
 {
     return(LZ4Engine64HC.SaveDictHC(_context, target, length));
 }
Пример #4
0
 /// <see cref="LZ4Encoder.EncodeBlock(byte*, int, byte*, int)"/>
 protected override int EncodeBlock(byte *source, int sourceLength, byte *target, int targetLength)
 {
     return(LZ4Engine64HC.CompressHCContinue(_context, source, target, sourceLength, targetLength));
 }