Example #1
0
        public static void Decompress(Stream newInStream, Stream newOutStream, ICodeProgress progress = null)
        {
            lock (m_DecoderLock)
            {
                if (m_Decoder == null)
                {
                    m_Decoder = new LzmaDecoder();
                }

                if (m_DecoderProps == null)
                {
                    m_DecoderProps = new byte[5];
                }
                if (newInStream.Read(m_DecoderProps, 0, 5) != 5) throw (new Exception("input .lzma is too short"));
                long outSize = 0;
                for (int i = 0; i < 8; i++)
                {
                    int v = newInStream.ReadByte();
                    if (v < 0) throw (new Exception("Can't Read 1"));
                    outSize |= ((long)(byte)v) << (8 * i);
                }

                m_Decoder.SetDecoderProperties(m_DecoderProps);
                long compressedSize = newInStream.Length - newInStream.Position;
                m_Decoder.Code(newInStream, newOutStream, compressedSize, outSize, progress);
            }
        }
Example #2
0
        /// <summary>
        /// Decompresses the given stream and writes to the output stream.
        /// </summary>
        /// <param name="newInStream">The input stream.</param>
        /// <param name="newOutStream">The output stream.</param>
        /// <param name="progress">The progress callback, if desired.</param>
        public static void Decompress(Stream newInStream, Stream newOutStream, ICodeProgress progress = null)
        {
            lock (m_DecoderLock)
            {
                if (m_Decoder == null)
                {
                    m_Decoder = new LzmaDecoder();
                }

                if (m_DecoderProps == null)
                {
                    m_DecoderProps = new byte[5];
                }
                if (newInStream.Read(m_DecoderProps, 0, 5) != 5)
                {
                    throw (new Exception("input .lzma is too short"));
                }
                long outSize = 0;
                for (int i = 0; i < 8; i++)
                {
                    int v = newInStream.ReadByte();
                    if (v < 0)
                    {
                        throw (new Exception("Can't Read 1"));
                    }
                    outSize |= ((long)(byte)v) << (8 * i);
                }

                m_Decoder.SetDecoderProperties(m_DecoderProps);
                long compressedSize = newInStream.Length - newInStream.Position;
                m_Decoder.Code(newInStream, newOutStream, compressedSize, outSize, progress);
            }
        }