Пример #1
0
        public static byte[] Decompress(Stream stream)
        {
            using (var br = new BinaryReader(stream, Encoding.Default, true))
            {
                int sizeAndMethod = br.ReadInt32();
                int size          = sizeAndMethod / 8;
                var method        = (Method)(sizeAndMethod % 8);

                switch (method)
                {
                case Method.NoCompression:
                    return(br.ReadBytes(size));

                case Method.LZSS:
                    return(LZSS.Decompress(br.BaseStream, size));

                case Method.Huffman4Bit:
                case Method.Huffman8Bit:
                    int num_bits = method == Method.Huffman4Bit ? 4 : 8;
                    return(Huffman.Decompress(br.BaseStream, num_bits, size));

                case Method.RLE:
                    return(RLE.Decompress(br.BaseStream, size));

                default:
                    throw new NotSupportedException($"Unknown compression method {method}");
                }
            }
        }
Пример #2
0
        public static byte[] Decompress(Stream input)
        {
            using (var br = new BinaryReaderX(input, true))
            {
                var method = (Method)br.ReadByte();

                switch (method)
                {
                case Method.LZ10:
                    br.BaseStream.Position--;
                    return(LZ10.Decompress(br.BaseStream));

                case Method.LZ11:
                    br.BaseStream.Position--;
                    return(LZ11.Decompress(br.BaseStream));

                case Method.Huff4:
                    br.BaseStream.Position--;
                    return(Huffman.Decompress(br.BaseStream, 4));

                case Method.Huff8:
                    br.BaseStream.Position--;
                    return(Huffman.Decompress(br.BaseStream, 8));

                case Method.RLE:
                    br.BaseStream.Position--;
                    return(RLE.Decompress(br.BaseStream));

                default:
                    br.BaseStream.Position--;
                    return(null);
                }
            }
        }
Пример #3
0
        public static byte[] Decompress(Stream input)
        {
            using (var br = new BinaryReaderX(input, true))
            {
                var methodSize = br.ReadUInt32();
                var method     = (Method)(methodSize & 0xff);
                int size       = (int)((methodSize & 0xffffff00) >> 8);

                using (var brB = new BinaryReaderX(new MemoryStream(br.ReadBytes((int)input.Length - 4))))
                    switch (method)
                    {
                    case Method.LZ10:
                        return(LZ10.Decompress(brB.BaseStream, size));

                    case Method.LZ11:
                        return(LZ11.Decompress(brB.BaseStream, size));

                    case Method.Huff4:
                        return(Huffman.Decompress(brB.BaseStream, 4, size, ByteOrder.BigEndian));

                    case Method.Huff8:
                        return(Huffman.Decompress(brB.BaseStream, 8, size));

                    case Method.RLE:
                        return(RLE.Decompress(brB.BaseStream, size));

                    case Method.LZ60:
                        throw new Exception("LZ60 isn't implemented yet");

                    //return LZ60.Decompress(brB.BaseStream);
                    default:
                        br.BaseStream.Position -= 4;
                        return(br.BaseStream.StructToBytes());
                    }
            }
        }