Example #1
0
        /// <summary>Created compression stream on top of inner stream.</summary>
        /// <param name="stream">Inner stream.</param>
        /// <param name="level">Compression level.</param>
        /// <param name="extraMemory">Extra memory used for compression.</param>
        /// <param name="leaveOpen">Leave inner stream open after disposing.</param>
        /// <returns>Compression stream.</returns>
        public static LZ4EncoderStream Encode(
            Stream stream, LZ4Level level, int extraMemory = 0,
            bool leaveOpen = false)
        {
            var settings = new LZ4EncoderSettings
            {
                ChainBlocks      = true,
                ExtraMemory      = extraMemory,
                BlockSize        = Mem.K64,
                CompressionLevel = level
            };

            return(Encode(stream, settings, leaveOpen));
        }
Example #2
0
        /// <summary>Created compression stream on top of inner stream.</summary>
        /// <param name="stream">Inner stream.</param>
        /// <param name="settings">Compression settings.</param>
        /// <param name="leaveOpen">Leave inner stream open after disposing.</param>
        /// <returns>Compression stream.</returns>
        public static LZ4EncoderStream Encode(
            Stream stream, LZ4EncoderSettings settings = null, bool leaveOpen = false)
        {
            settings = settings ?? LZ4EncoderSettings.Default;
            var frameInfo = new LZ4Descriptor(
                settings.ContentLength,
                settings.ContentChecksum,
                settings.ChainBlocks,
                settings.BlockChecksum,
                settings.Dictionary,
                settings.BlockSize);
            var level       = settings.CompressionLevel;
            var extraMemory = settings.ExtraMemory;

            return(new LZ4EncoderStream(
                       stream,
                       frameInfo,
                       i => LZ4Encoder.Create(
                           i.Chaining, level, i.BlockSize, ExtraBlocks(i.BlockSize, extraMemory)),
                       leaveOpen));
        }