Exemplo 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);
                        }
                    }
        }
        public static LZ4Settings ParseSettings(string options)
        {
            var result = new LZ4Settings {
                Chaining = false
            };

            foreach (var option in options.Split(' '))
            {
                switch (option)
                {
                case "-1":
                    result.Level = LZ4Level.L00_FAST;
                    break;

                case "-9":
                    result.Level = LZ4Level.L09_HC;
                    break;

                case "-11":
                    result.Level = LZ4Level.L11_OPT;
                    break;

                case "-12":
                    result.Level = LZ4Level.L12_MAX;
                    break;

                case "-BD":
                    result.Chaining = true;
                    break;

                case "-BX":
                    // ignored to be implemented
                    break;

                case "-B4":
                    result.BlockSize = Mem.K64;
                    break;

                case "-B5":
                    result.BlockSize = Mem.K256;
                    break;

                case "-B6":
                    result.BlockSize = Mem.M1;
                    break;

                case "-B7":
                    result.BlockSize = Mem.M4;
                    break;

                default:
                    throw new NotImplementedException($"Option '{option}' not recognized");
                }
            }

            return(result);
        }