Flush() public method

Flushes the baseInputStream
public Flush ( ) : void
return void
Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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;
 }