Ejemplo n.º 1
0
        public static void Encode(
            string original, string encoded, int chuckSize, LZ4Settings settings)
        {
            var frameInfo = new LZ4Descriptor(
                null, false, settings.Chaining, false, null, settings.BlockSize);

            using (var input = File.OpenRead(original))
                using (var output = File.Create(encoded))
                    using (var encode = new LZ4EncoderStream(
                               output, frameInfo, i => LZ4Encoder.Create(
                                   i.Chaining, settings.Level, i.BlockSize, settings.ExtraBlocks)))
                    {
                        var buffer = new byte[chuckSize];
                        while (true)
                        {
                            var read = input.Read(buffer, 0, buffer.Length);
                            if (read == 0)
                            {
                                break;
                            }

                            encode.Write(buffer, 0, read);
                        }
                    }
        }
Ejemplo n.º 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 LZ4FrameInfo(
                settings.ContentLength,
                settings.ContentChecksum,
                settings.ChainBlocks,
                settings.BlockChecksum,
                settings.BlockSize);
            var level       = settings.CompressionLevel;
            var extraMemory = settings.ExtraMemory;

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