Exemplo n.º 1
0
        /// <summary>
        /// Creates a decompression stream on top of the <see cref="Stream"/> specified.
        /// </summary>
        /// <param name="stream">Inner stream.</param>
        /// <param name="settings">Decompression settings.</param>
        /// <param name="leaveOpen">Leave inner stream open after disposing.</param>
        /// <returns>
        /// The decompression stream.
        /// </returns>
        public static LZ4DecoderStream Decode(Stream stream, LZ4DecoderSettings settings = null, bool leaveOpen = false)
        {
            settings = settings ?? LZ4DecoderSettings.Default;
            int extraMemory = settings.ExtraMemory;

            return(new LZ4DecoderStream(
                       stream,
                       i => LZ4EncodingFactory.CreateDecoder(i.Chaining, i.BlockSize, ExtraBlocks(i.BlockSize, extraMemory)),
                       leaveOpen));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a compression stream on top of the <see cref="Stream"/> specified.
        /// </summary>
        /// <param name="stream">Inner stream.</param>
        /// <param name="settings">Compression settings.</param>
        /// <param name="leaveOpen">Leave inner stream open after disposing.</param>
        /// <returns>
        /// The compression stream.
        /// </returns>
        public static LZ4EncoderStream Encode(Stream stream, LZ4EncoderSettings settings = null, bool leaveOpen = false)
        {
            settings = settings ?? LZ4EncoderSettings.Default;

            LZ4FrameDescriptor frameInfo = new LZ4FrameDescriptor(
                settings.ContentLength,
                settings.ContentChecksum,
                settings.ChainBlocks,
                settings.BlockChecksum,
                settings.Dictionary,
                settings.BlockSize);

            LZ4CompressionLevel level = settings.CompressionLevel;
            int extraMemory           = settings.ExtraMemory;

            return(new LZ4EncoderStream(
                       stream,
                       frameInfo,
                       i => LZ4EncodingFactory.CreateEncoder(i.Chaining, level, i.BlockSize, ExtraBlocks(i.BlockSize, extraMemory)),
                       leaveOpen));
        }
Exemplo n.º 3
0
        public static void Encode(string original, string encoded, int chuckSize, LZ4Settings settings)
        {
            var frameInfo = new LZ4FrameDescriptor(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 => LZ4EncodingFactory.CreateEncoder(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);
                        }
                    }
        }