Exemplo n.º 1
0
        /// <summary>
        /// 압축된 데이타를 복원한다.
        /// </summary>
        /// <param name="input">복원할 Data</param>
        /// <returns>복원된 Data</returns>
        public override byte[] Decompress(byte[] input)
        {
            if (IsDebugEnabled)
            {
                log.Debug(CompressorTool.SR.DecompressStartMsg);
            }

            // check input data
            if (input.IsZeroLength())
            {
                if (log.IsWarnEnabled)
                {
                    log.Warn(CompressorTool.SR.InvalidInputDataMsg);
                }

                return(new byte[0]);
            }

            byte[] properties2 = new byte[5];

            byte[] output;

            using (var outStream = new MemoryStream())
                using (var inStream = new MemoryStream(input)) {
                    var decoder = new NSoft.NFramework.Compressions.SevenZip.Compression.LZMA.LzmaDecoder();

                    inStream.Seek(0, SeekOrigin.Begin);

                    if (inStream.Read(properties2, 0, 5) != 5)
                    {
                        throw new InvalidOperationException("input 7Zip.LZMA is too short.");
                    }

                    long outSize = 0;
                    for (int i = 0; i < 8; i++)
                    {
                        int v = inStream.ReadByte();
                        if (v < 0)
                        {
                            throw new InvalidOperationException("Can't Read 1");
                        }

                        outSize |= ((long)(byte)v) << (8 * i);
                    }

                    decoder.SetDecoderProperties(properties2);

                    long compressedSize = inStream.Length - inStream.Position;
                    decoder.Code(inStream, outStream, compressedSize, outSize, null);

                    output = outStream.ToArray();
                }

            if (IsDebugEnabled)
            {
                log.Debug(CompressorTool.SR.DecompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);
            }

            return(output ?? new byte[0]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 압축된 데이타를 복원한다.
        /// </summary>
        /// <param name="input">복원할 Data</param>
        /// <returns>복원된 Data</returns>
        public override byte[] Decompress(byte[] input) {
            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.DecompressStartMsg);

            // check input data
            if(input.IsZeroLength()) {
                if(log.IsWarnEnabled)
                    log.Warn(CompressorTool.SR.InvalidInputDataMsg);

                return new byte[0];
            }

            byte[] properties2 = new byte[5];

            byte[] output;

            using(var outStream = new MemoryStream())
            using(var inStream = new MemoryStream(input)) {
                var decoder = new NSoft.NFramework.Compressions.SevenZip.Compression.LZMA.LzmaDecoder();

                inStream.Seek(0, SeekOrigin.Begin);

                if(inStream.Read(properties2, 0, 5) != 5)
                    throw new InvalidOperationException("input 7Zip.LZMA is too short.");

                long outSize = 0;
                for(int i = 0; i < 8; i++) {
                    int v = inStream.ReadByte();
                    if(v < 0)
                        throw new InvalidOperationException("Can't Read 1");

                    outSize |= ((long)(byte)v) << (8 * i);
                }

                decoder.SetDecoderProperties(properties2);

                long compressedSize = inStream.Length - inStream.Position;
                decoder.Code(inStream, outStream, compressedSize, outSize, null);

                output = outStream.ToArray();
            }

            if(IsDebugEnabled)
                log.Debug(CompressorTool.SR.DecompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);

            return output ?? new byte[0];
        }