Exemplo n.º 1
0
        private void InflateStream(Stream i, Stream o)
        {
            InflaterInputStream inf = new InflaterInputStream(i, new Inflater(true), 0x400);

            Util.StreamCopy(o, inf, long.MaxValue);
            inf.Flush();
        }
Exemplo n.º 2
0
        public static byte[] Decompress(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException();
            }
            if (count < 0)
            {
                throw new FormatException();
            }
            if (offset + count > buffer.Length)
            {
                throw new IndexOutOfRangeException();
            }

            using (MemoryStream buffStream = new MemoryStream(buffer, offset, count))
            {
                InflaterInputStream zipStream;
                uint magicStream = buffStream.ReadValueU32();
                if (magicStream != magic && magicStream.Swap() != magic)
                {
                    throw new InvalidDataException("found an invalid zlib block");
                }

                uint buffMaxSegmentSize = buffStream.ReadValueU32();
                if (buffMaxSegmentSize != maxSegmentSize)
                {
                    throw new FormatException();
                }

                uint totComprSize   = buffStream.ReadValueU32();
                uint totUncomprSize = buffStream.ReadValueU32();

                byte[] outputBuffer = new byte[totUncomprSize];
                int    numOfSegm    = (int)Math.Ceiling((double)totUncomprSize / (double)maxSegmentSize);
                int    headSegm     = 16;
                int    dataSegm     = headSegm + (numOfSegm * 8);
                int    buffOff      = 0;

                for (int i = 0; i < numOfSegm; i++)
                {
                    buffStream.Seek(headSegm, SeekOrigin.Begin);
                    int comprSegm   = buffStream.ReadValueS32();
                    int uncomprSegm = buffStream.ReadValueS32();
                    headSegm = (int)buffStream.Position;

                    buffStream.Seek(dataSegm, SeekOrigin.Begin);
                    //Console.WriteLine("compr size: {0}, uncompr size: {1}, data offset: 0x{2:X8}", comprSegm, uncomprSegm, dataSegm);
                    zipStream = new InflaterInputStream(buffStream);
                    zipStream.Read(outputBuffer, buffOff, uncomprSegm);
                    zipStream.Flush();
                    buffOff  += uncomprSegm;
                    dataSegm += comprSegm;
                }
                buffStream.Close();
                return(outputBuffer);
            }
        }
Exemplo n.º 3
0
        public static byte[] DecompressZlib(byte[] input, int size)
        {
            byte[] result = new byte[size];
            InflaterInputStream zipStream = new InflaterInputStream(new MemoryStream(input));

            zipStream.Read(result, 0, size);
            zipStream.Flush();
            return(result);
        }
Exemplo n.º 4
0
 public static void Decompress(Stream stream, byte[] input)
 {
     using (var zlib = new InflaterInputStream(stream)) {
         zlib.IsStreamOwner = false;
         zlib.Write(input, 0, input.Length);
         zlib.Flush();
         zlib.Close();
     }
 }
Exemplo n.º 5
0
 public static byte[] Decompress(byte[] input)
 {
     using (var mem = new MemoryStream()) {
         using (var zlib = new InflaterInputStream(mem)) {
             zlib.Write(input, 0, input.Length);
             zlib.Flush();
             zlib.Close();
             return(mem.ToArray());
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Uncompresses the provided input data using zlib inflater.
        /// </summary>
        /// <param name="inputData">The input data.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static IEnumerable <byte> InflateUncompress(byte[] inputData)
        {
            inputData.ThrowIfNull(nameof(inputData));

            using (MemoryStream inputStream = GetMemoryStream(inputData))
                using (MemoryStream outputStream = GetMemoryStream())
                {
                    InflaterInputStream deflaterOutputStream = new InflaterInputStream(inputStream);
                    deflaterOutputStream.CopyTo(outputStream);
                    deflaterOutputStream.Flush();

                    return(outputStream.ToArray());
                }
        }
Exemplo n.º 7
0
 private byte[] UncompressBlock(Stream s, uint CompSize, uint UnCompSize)
 {
     byte[] res = new byte[UnCompSize];
     try
     {
         InflaterInputStream zipstream = new InflaterInputStream(s);
         zipstream.Read(res, 0, (int)UnCompSize);
         zipstream.Flush();
     }
     catch (Exception ex)
     {
         DebugLog.PrintLn("PCCPACKAGE::UNCOMPRESSBLOCK ERROR:\n" + ex.Message);
     }
     return(res);
 }
Exemplo n.º 8
0
        public static byte[] DeCompress(byte [] b)
        {
            Stream s2 = new InflaterInputStream(new MemoryStream(b));

            try
            {
                byte [] dest = null;
                int     size = s2.Read(writeData, 0, writeData.Length);
                if (size > 0)
                {
                    dest = new byte[size];
                    Buffer.BlockCopy(writeData, 0, dest, 0, size);
                }
                s2.Flush();
                s2.Close();
                return(dest);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(null);
            }
        }
Exemplo n.º 9
0
 public override void Flush()
 {
     ist.Flush();
 }
 public override void Flush() => ist.Flush();