Read() public méthode

Reads decompressed data into the provided buffer byte array
/// Inflater needs a dictionary ///
public Read ( byte buffer, int offset, int count ) : int
buffer byte /// The array to read and decompress data into ///
offset int /// The offset indicating where the data should be placed ///
count int /// The number of bytes to decompress ///
Résultat int
Exemple #1
0
        /// <summary>
        /// Decompresses an array of bytes.
        /// </summary>
        /// <param name="_pBytes">An array of bytes to be decompressed.</param>
        /// <returns>Decompressed bytes</returns>
        public static byte[] DeCompress(byte[] _pBytes)
        {
            InflaterInputStream inputStream = new InflaterInputStream(new MemoryStream(_pBytes));

            MemoryStream ms = new MemoryStream();
            Int32 mSize;

            byte[] mWriteData = new byte[4096];

            while (true)
            {
                mSize = inputStream.Read(mWriteData, 0, mWriteData.Length);
                if (mSize > 0)
                {
                    ms.Write(mWriteData, 0, mSize);
                }
                else
                {
                    break;
                }
            }

            inputStream.Close();
            return ms.ToArray();
        }
Exemple #2
0
        public static byte[] DecompressGzipBytes(byte[] Bytes)
        {
            ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream stream =
                new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(new MemoryStream(Bytes));

            MemoryStream memory = new MemoryStream();

            byte[] writeData = new byte[4096];
            int    size;

            while (true)
            {
                size = stream.Read(writeData, 0, writeData.Length);
                if (size > 0)
                {
                    memory.Write(writeData, 0, size);
                }
                else
                {
                    break;
                }
            }

            stream.Close();

            return(memory.ToArray());
        }
        public void TestInflateDeflate()
        {
            MemoryStream ms = new MemoryStream();
            Deflater deflater = new Deflater(6);
            DeflaterOutputStream outStream = new DeflaterOutputStream(ms, deflater);

            byte[] buf = new byte[1000000];
            System.Random rnd = new Random();
            rnd.NextBytes(buf);

            outStream.Write(buf, 0, buf.Length);
            outStream.Flush();
            outStream.Finish();

            ms.Seek(0, SeekOrigin.Begin);

            InflaterInputStream inStream = new InflaterInputStream(ms);
            byte[] buf2 = new byte[buf.Length];
            int    pos  = 0;
            while (true) {
                int numRead = inStream.Read(buf2, pos, 4096);
                if (numRead <= 0) {
                    break;
                }
                pos += numRead;
            }

            for (int i = 0; i < buf.Length; ++i) {
                Assertion.AssertEquals(buf2[i], buf[i]);
            }
        }
        public string Decompress(string compressedString)
        {
            var uncompressedString = string.Empty;
            var totalLength = 0;
            var inputAsBytes = Convert.FromBase64String(compressedString);;
            var writeData = new byte[4096];
            var inputStream = new InflaterInputStream(new MemoryStream(inputAsBytes));

            for(;;)
            {
                var size = inputStream.Read(writeData, 0, writeData.Length);

                if (size > 0)
                {
                    totalLength += size;
                    uncompressedString += Encoding.UTF8.GetString(writeData, 0, size);
                }
                else
                {
                    break;
                }
            }

            inputStream.Close();

            return uncompressedString;
        }
		void Inflate(MemoryStream ms, byte[] original, int level, bool zlib)
		{
			ms.Seek(0, SeekOrigin.Begin);
			
			Inflater inflater = new Inflater(!zlib);
			InflaterInputStream inStream = new InflaterInputStream(ms, inflater);
			byte[] buf2 = new byte[original.Length];

			int currentIndex  = 0;
			int count = buf2.Length;

			try
			{
				while (true) 
				{
					int numRead = inStream.Read(buf2, currentIndex, count);
					if (numRead <= 0) 
					{
						break;
					}
					currentIndex += numRead;
					count -= numRead;
				}
			}
			catch(Exception ex)
			{
				Console.WriteLine("Unexpected exception - '{0}'", ex.Message);
				throw;
			}

			if ( currentIndex != original.Length )
			{
				Console.WriteLine("Original {0}, new {1}", original.Length, currentIndex);
				Assert.Fail("Lengths different");
			}

			for (int i = 0; i < original.Length; ++i) 
			{
				if ( buf2[i] != original[i] )
				{
					string description = string.Format("Difference at {0} level {1} zlib {2} ", i, level, zlib);
					if ( original.Length < 2048 )
					{
						StringBuilder builder = new StringBuilder(description);
						for (int d = 0; d < original.Length; ++d)
						{
							builder.AppendFormat("{0} ", original[d]);
						}

						Assert.Fail(builder.ToString());
					}
					else
					{
						Assert.Fail(description);
					}
				}
			}
		}
Exemple #6
0
 public void Decompress(ArraySegment<byte> input, ArraySegment<byte> output)
 {
     using (var gz = new InflaterInputStream(new MemoryStream(input.Array, input.Offset, input.Count)))
     {
         int read = gz.Read(output.Array, output.Offset, output.Count);
         if (read != output.Count)
             throw new Exception("Short read!");
     }
 }
Exemple #7
0
        public static byte[] Decompress(byte[] data, int final_size)
        {
            byte[] r = null;

            using (Stream s = new InflaterInputStream(new MemoryStream(data)))
                s.Read(r, 0, final_size);

            return r;
        }
        public static byte[] UncompressStream(Stream stream, int filesize, int memsize)
        {

            BinaryReader r = new BinaryReader(stream);
            long end = stream.Position + filesize;

            byte[] header = r.ReadBytes(2);

            if (checking) if (header.Length != 2)
                    throw new InvalidDataException("Hit unexpected end of file at " + stream.Position);

            bool useDEFLATE = true;
            byte[] uncompressedData = null;

            if (header[0] == 0x78)
            {
                useDEFLATE = true;
            }
            else if (header[1] == 0xFB)
            {
                useDEFLATE = false;
            }
            else
            {
                throw new InvalidDataException("Unrecognized compression format");
            }

            if (useDEFLATE)
            {
                byte[] data = new byte[filesize];
                stream.Position -= 2; // go back to header
                stream.Read(data, 0, filesize);
                using (MemoryStream source = new MemoryStream(data))
                {
                    using (InflaterInputStream decomp = new InflaterInputStream(source))
                    {
                        uncompressedData = new byte[memsize];
                        decomp.Read(uncompressedData, 0, memsize);
                    }
                }
            }
            else
            {
                uncompressedData = OldDecompress(stream, header[0]);
            }

            long realsize = uncompressedData.Length;

            if (checking) if (realsize != memsize)
                    throw new InvalidDataException(String.Format(
                        "Resource data indicates size does not match index at 0x{0}.  Read 0x{1}.  Expected 0x{2}.",
                        stream.Position.ToString("X8"), realsize.ToString("X8"), memsize.ToString("X8")));

            return uncompressedData;

        }
Exemple #9
0
 public byte[] Decode(byte[] input, int decompressedSize)
 {
     InflaterInputStream stream = new InflaterInputStream(new MemoryStream(input));
     byte[] data = new byte[4096];
     MemoryStream outStream = new MemoryStream();
     int size;
     while ((size = stream.Read(data, 0, data.Length)) > 0)
     {
         outStream.Write(data, 0, size);
     }
     outStream.Capacity = (int)outStream.Length;
     return outStream.GetBuffer();
 }
Exemple #10
0
        public static byte[] Decompress(byte[] data)
        {
            byte[] r = null;

            using (Stream s = new InflaterInputStream(new MemoryStream(data)))
            {
                byte[] b = new byte[8192];
                int count = s.Read(b, 0, b.Length);
                r = b.Take(count).ToArray();
            }

            return r;
        }
Exemple #11
0
 // Length = decompressed length
 public static byte[] Decompress(int Length, byte[] Data)
 {
     byte[] Output = new byte[Length];
     Stream s = new InflaterInputStream(new MemoryStream(Data));
     int Offset = 0;
     while(true)
     {
         int size = s.Read(Output, Offset, Length);
         if (size == Length) break;
         Offset += size;
         Length -= size;
     }
     return Output;
 }
 public static byte[] Decompress(string data)
 {
     byte[] array = null;
     if (data.StartsWith("ZipStream:"))
     {
         MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(data.Substring(10)));
         InflaterInputStream inflaterInputStream = new InflaterInputStream(memoryStream);
         BinaryReader binaryReader = new BinaryReader(memoryStream);
         int num = binaryReader.ReadInt32();
         array = new byte[num];
         inflaterInputStream.Read(array, 0, num);
         inflaterInputStream.Close();
         memoryStream.Close();
     }
     return array;
 }
Exemple #13
0
 public static void Decompress(ref GenericReader gr)
 {
     int uncompressedLength = gr.ReadInt32();
     byte[] output = new byte[gr.ReadInt32()];
     byte[] temp = gr.ReadBytes((int)gr.Remaining);
     gr.Close();
     Stream s = new InflaterInputStream(new MemoryStream(temp));
     int offset = 0;
     while (true)
     {
         int size = s.Read(output, offset, uncompressedLength);
         if (size == uncompressedLength) break;
         offset += size;
         uncompressedLength -= size;
     }
     gr = new GenericReader(new MemoryStream(output));
     //gr.BaseStream.Position = 0;
 }
Exemple #14
0
 public static GenericReader Decompress(GenericReader gr)
 {
     int uncompressedLength = gr.ReadInt32();
     byte[] input = gr.ReadBytes((int)gr.Remaining);
     byte[] output = new byte[uncompressedLength];
     gr.Close();
     InflaterInputStream istream = new InflaterInputStream(new MemoryStream(input));
     int offset = 0;
     while (true)
     {
         int size = istream.Read(output, offset, uncompressedLength);
         if (size == uncompressedLength)
             break;
         offset += size;
         uncompressedLength -= size;
     }
     return new GenericReader(new MemoryStream(output));
 }
        public string Inflate(byte[] gzBuffer)
        {
            using (var ms = new MemoryStream())
            {
                var msgLength = BitConverter.ToInt32(gzBuffer, 0);
                ms.Write(gzBuffer, 4, gzBuffer.Length - 4);

                var buffer = new byte[msgLength];

                ms.Position = 0;
                using (var zipStream = new InflaterInputStream(ms, new Inflater()))
                {
                    zipStream.Read(buffer, 0, buffer.Length);
                }

                return Encoding.UTF8.GetString(buffer);
            }
        }
Exemple #16
0
 public byte[] Decompress( byte[] bytes )
 {
     Stream stream = new InflaterInputStream( new MemoryStream( bytes ) );
     MemoryStream memory = new MemoryStream();
     int totalLength = 0;
     byte[] writeData = new byte[4096];
     while ( true )
     {
         int size = stream.Read( writeData, 0, writeData.Length );
         if ( size > 0 )
         {
             totalLength += size;
             memory.Write( writeData, 0, size );
         }
         else
             break;
     }
     stream.Close();
     return memory.ToArray();
 }
Exemple #17
0
 public static byte[] Decompress(byte[] bytes)
 {
     InflaterInputStream stream = new InflaterInputStream(new MemoryStream(bytes));
     MemoryStream memory = new MemoryStream();
     Byte[] writeData = new byte[4096];
     int size;
     while (true)
     {
         size = stream.Read(writeData, 0, writeData.Length);
         if (size > 0)
         {
             memory.Write(writeData, 0, size);
         }
         else
         {
             break;
         }
     }
     stream.Close();
     return memory.ToArray();
 }
Exemple #18
0
 public static MemoryStream ProcessData(byte[] data)
 {
     if (data == null)
     {
         return null;
     }
     MemoryStream baseInputStream = null;
     MemoryStream stream2;
     InflaterInputStream stream3 = null;
     try
     {
         baseInputStream = new MemoryStream(data);
         stream2 = new MemoryStream();
         stream3 = new InflaterInputStream(baseInputStream);
         byte[] buffer = new byte[data.Length];
         while (true)
         {
             int count = stream3.Read(buffer, 0, buffer.Length);
             if (count <= 0)
             {
                 break;
             }
             stream2.Write(buffer, 0, count);
         }
         stream2.Flush();
         stream2.Seek(0L, SeekOrigin.Begin);
     }
     finally
     {
         if (baseInputStream != null)
         {
             baseInputStream.Close();
         }
         if (stream3 != null)
         {
             stream3.Close();
         }
     }
     return stream2;
 }
Exemple #19
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;
     }
 }
Exemple #20
0
        public string Decompress(byte[] baseBytes)
        {
            string resultStr = string.Empty;
            using (MemoryStream memoryStream = new MemoryStream(baseBytes))
            {
                using (InflaterInputStream inf = new InflaterInputStream(memoryStream))
                {
                    using (MemoryStream buffer = new MemoryStream())
                    {
                        byte[] result = new byte[1024];

                        int resLen;
                        while ((resLen = inf.Read(result, 0, result.Length)) > 0)
                        {
                            buffer.Write(result, 0, resLen);
                        }
                        resultStr = Encoding.Default.GetString(result);
                    }
                }
            }
            return resultStr;
        }
 private byte[] UncompressedImage()
 {
     using (MemoryStream stream = new MemoryStream(_payload))
     {
         using (BinaryReader br = new BinaryReader(stream))
         {
             br.BaseStream.Position += 3;
             ushort compressed = br.ReadUInt16();
             ushort uncompressed = br.ReadUInt16();
             ushort width = br.ReadUInt16();
             ushort height = br.ReadUInt16();
             byte[] compressedImage = br.ReadBytes((int)compressed);
             using (MemoryStream str = new MemoryStream(compressedImage))
             {
                 using (InflaterInputStream zlip = new InflaterInputStream(str))
                 {
                     byte[] buffer = new byte[51200];
                     zlip.Read(buffer, 0, uncompressed);
                     return UncompressedImg(width, height, buffer);
                 }
             }
         }
     }
 }
Exemple #22
0
        /* Private methods */
        private void readCMV(string inFilename)
        {
            byte[] source, decompressed;
            ExtensionType extension;
            InflaterInputStream zipInStream;
            Stream stream;
            FileStream fileStream;
            MemoryStream memoryStream;

            extension = checkExtension(inFilename);

            if (extension == ExtensionType.CCMV)
            {
                source = File.ReadAllBytes(inFilename);
                decompressed = new byte[0];

                memoryStream = new MemoryStream(source);
                zipInStream = new InflaterInputStream(memoryStream);
                zipInStream.Read(decompressed, 0, decompressed.Length);
                stream = new MemoryStream(decompressed);
            }
            else
            {
                fileStream = File.OpenRead(inFilename);
                stream = fileStream;
            }

            byte[] intBytes = new byte[4];

            stream.Read(intBytes, 0, 4);
            version = BitConverter.ToUInt32(intBytes, 0);

            stream.Read(intBytes, 0, 4);
            cols = BitConverter.ToUInt32(intBytes, 0);

            stream.Read(intBytes, 0, 4);
            rows = BitConverter.ToUInt32(intBytes, 0);

            stream.Read(intBytes, 0, 4);
            delayRate = BitConverter.ToUInt32(intBytes, 0);

            // Sounds
            if (version == 10001)
            {
                stream.Read(intBytes, 0, 4);
                numSounds = BitConverter.ToInt32(intBytes, 0);

                soundNames = new byte[50 * numSounds];
                stream.Read(soundNames, 0, 50 * numSounds);

                soundTimings = new byte[200 * NUM_SOUNDCHANNELS]; // 0x3200
                stream.Read(soundTimings, 0, 200 * NUM_SOUNDCHANNELS);
            }

            int frameSize = (int)(cols * rows);
            frameSize += frameSize;

            byte[] previousFrame = new byte[frameSize];
            for (int frameByte = 0; frameByte < frameSize; frameByte++)
            {
                previousFrame[frameByte] = 0;
            }

            byte[] curFrame = new byte[frameSize];
            int framesDone = 0;
            int frameSizeLeft = frameSize;
            int frameSizeDone = 0;

            while (stream.Position < stream.Length)
            {
                if (stream.Read(intBytes, 0, 4) == 4)
                {
                    int compressedChunkSize = BitConverter.ToInt32(intBytes, 0);
                    byte[] buffer = new byte[compressedChunkSize];
                    stream.Read(buffer, 0, compressedChunkSize);

                    memoryStream = new MemoryStream(buffer);
                    zipInStream = new InflaterInputStream(memoryStream);

                    int bytesRead = 0;
                    do
                    {
                        bytesRead = zipInStream.Read(curFrame, frameSizeDone, frameSizeLeft);

                        if (bytesRead == frameSizeLeft)
                        {
                            /*
                             * Valid variables at this point:
                             * frameSize
                             * byte[frameSize] previousFrame
                             * byte[frameSize] curFrame
                             */

                            framesDone++;

                            frames.Add(new CMVFrame(curFrame, cols, rows));
                            Array.Copy(curFrame, previousFrame, frameSize);

                            frameSizeLeft = frameSize;
                            frameSizeDone = 0;
                        }
                        else
                        {
                            frameSizeDone += bytesRead;
                            frameSizeLeft -= bytesRead;
                        }
                    } while (bytesRead == frameSize);
                }
                else
                {
                    break;
                }
            }

            stream.Close();
            stream.Dispose();
        }
Exemple #23
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;
 }
        public Packet[] Uncompress()
        {
            System.IO.Stream msStream = new System.IO.MemoryStream(bCompressedData);
            InflaterInputStream iisUnpack = new InflaterInputStream(msStream, new Inflater(true));
            byte[] bOutput = new byte[0];
            try {
                byte[] bWorkout = new byte[4096];
                int iSize = iisUnpack.Read(bWorkout, 0, bWorkout.Length);
                while (iSize > 0) {
                    byte[] bOldOutput = new byte[bOutput.Length];
                    bOutput.CopyTo(bOldOutput, 0);
                    bOutput = new byte[bOutput.Length + iSize];
                    bOldOutput.CopyTo(bOutput, 0);
                    Array.Copy(bWorkout, 0, bOutput, bOldOutput.Length, iSize);
                    iSize = iisUnpack.Read(bWorkout, 0, bWorkout.Length);
                }
                iisUnpack.Close();
            } catch (Exception e) {
                // TODO - Throw the exception in the main application
                // System.Windows.Forms.MessageBox.Show(e.ToString());
                throw new System.Exception("Error uncompressing the message: " + e.Message);
            }

            return Packet.ParsePackets(bOutput);
        }
        private List<byte> Decompress(FileStream data, long offset, long length)
        {
            var t = new List<byte>();
            var inflator = new Inflater();
            Stream stream = CopyStream(data, offset, (int) length);
            var in1 = new InflaterInputStream(stream, inflator, 1024*8);

            var buffer = new byte[1024*8];
            int len;
            while ((len = in1.Read(buffer, 0, 1024*8)) > 0)
            {
                for (int i = 0; i < len; i++)
                {
                    t.Add(buffer[i]);
                }
            }
            return t;
        }
Exemple #26
0
        private void Decompress()
        {
            byte[] data = new byte[Length - 8];
            var iis = new InflaterInputStream(mBitStream.BaseStream);
            int i = 0, j;

            do
            {
                j = iis.Read(data, i, data.Length - i);
                if (j <= 0) throw new EndOfStreamException();
                i += j;
            }
            while(i < data.Length);
            mBitStream = new BitStream(new MemoryStream(data));
        }
Exemple #27
0
        Tuple<PackObjectType, byte[]> readLooseObject(FileInfo objectFi)
        {
            ObjectId objId = ObjectId.Parse(objectFi.Directory.Name + objectFi.Name);

            var sha = SHA1.Create();
            string tag;
            byte[] objectContents;

            using (var fs = objectFi.OpenRead())
            {
                //TODO: apply some not-invented-here syndrom by reimplmenting inflate
                using (var inflater = new InflaterInputStream(fs))
                {
                    int? spaceNdx = null;
                    int headerBytesRead = 0;
                    byte[] headerBytes = new byte[30]; //should be enough for a 64-bit size
                    while (true)
                    {
                        int b = inflater.ReadByte();
                        if (b == -1)
                            throw new Exception("Unexpected EOF");

                        headerBytes[headerBytesRead] = (byte)b;

                        if (b == ' ')
                            spaceNdx = headerBytesRead;

                        headerBytesRead++;

                        if (b == 0)
                            break;

                        if (headerBytesRead == headerBytes.Length)
                            throw new Exception("Header too big.");
                    }
                    if (!spaceNdx.HasValue)
                        throw new Exception("Did not find space.");

                    //split the string along the space to get the object type and size and size
                    tag = Encoding.ASCII.GetString(headerBytes, 0, spaceNdx.Value);
                    string sizeStr = Encoding.ASCII.GetString(headerBytes, spaceNdx.Value + 1, headerBytesRead - spaceNdx.Value - 2);
                    int objectSize = int.Parse(sizeStr, NumberStyles.None, CultureInfo.InvariantCulture);
                    objectContents = new byte[objectSize];
                    if (inflater.Read(objectContents, 0, objectSize) != objectSize)
                        throw new Exception("Short read.");

                    sha.TransformBlock(headerBytes, 0, headerBytesRead, null, 0);
                }
            }

            sha.TransformFinalBlock(objectContents, 0, objectContents.Length);
            if (!objId.Equals(new ObjectId(sha.Hash)))
                throw new Exception("Hash is not right!");

            PackObjectType objType;
            switch (tag)
            {
                case "blob":
                    objType = PackObjectType.Blob;
                    break;
                case "commit":
                    objType = PackObjectType.Commit;
                    break;
                case "tree":
                    objType = PackObjectType.Tree;
                    break;
                case "tag":
                    objType = PackObjectType.Tag;
                    break;
                default:
                    throw new Exception("Unrecognized object type: " + tag);
            }

            return new Tuple<PackObjectType, byte[]>(objType, objectContents);
        }
Exemple #28
0
        private Object GetObjectLoose(string aId)
        {
            var path = Path.Combine(iFolderObjects.FullName, aId.Substring(0, 2), aId.Substring(2, 38));

            try
            {
                var file = File.OpenRead(path);

                using (var inflater = new InflaterInputStream(file))
                {
                    int offset = 0;

                    byte[] header = new byte[100];

                    while (true)
                    {
                        int b = inflater.ReadByte();

                        if (b == 0)
                        {
                            break;
                        }

                        if (offset >= 100)
                        {
                            throw (new GitException("Illegal object header " + aId));
                        }

                        header[offset++] = (byte)b;
                    }

                    string[] parts = ASCIIEncoding.ASCII.GetString(header, 0, offset).Split(new char[] { ' ' });

                    if (parts.Length != 2)
                    {
                        throw (new GitException("Illegal object header " + aId));
                    }

                    int length;

                    if (!int.TryParse(parts[1], out length))
                    {
                        throw (new GitException("Illegal object length " + aId));
                    }

                    byte[] bytes = new byte[length];

                    inflater.Read(bytes, 0, length);

                    switch (parts[0])
                    {
                        case "commit":
                            return (new Object(EObjectType.Commit, bytes));
                        case "tag":
                            return (new Object(EObjectType.Tag, bytes));
                        case "tree":
                            return (new Object(EObjectType.Tree, bytes));
                        case "blob":
                            return (new Object(EObjectType.Blob, bytes));
                        default:
                            throw (new GitException("Unrecognised object type " + aId));
                    }
                }
            }
            catch (FileNotFoundException)
            {
                return (null);
            }
        }
Exemple #29
0
        /// <summary>
        /// Decompresses the provided data, returning the inflated result.
        /// </summary>
        /// <param name="data">the deflated picture data.</param>
        /// <returns>the inflated picture data.</returns>
        private static byte[] InflatePictureData(byte[] data)
        {
            using (MemoryStream in1 = new MemoryStream(data))
            {
                using (MemoryStream out1 = new MemoryStream())
                {
                    InflaterInputStream zIn = null;
                    try
                    {
                        Inflater inflater = new Inflater(false);
                        zIn = new InflaterInputStream(in1, inflater);

                        byte[] buf = new byte[4096];
                        int ReadBytes;
                        while ((ReadBytes = zIn.Read(buf, 0, buf.Length)) > 0)
                        {
                            out1.Write(buf, 0, ReadBytes);
                        }
                        return out1.ToArray();
                    }
                    catch (IOException e)
                    {
                        log.Log(POILogger.WARN, "Possibly corrupt compression or non-compressed data", e);
                        return data;
                    }
                }
            }
        }
 /// <summary>
 /// Decompresses the provided data, returning the inflated result.
 /// </summary>
 /// <param name="data">the deflated picture data.</param>
 /// <returns>the inflated picture data.</returns>
 private static byte[] InflatePictureData(byte[] data)
 {
     try
     {
         InflaterInputStream in1 = new InflaterInputStream(
             new MemoryStream(data));
         MemoryStream out1 = new MemoryStream();
         byte[] buf = new byte[4096];
         int ReadBytes;
         while ((ReadBytes = in1.Read(buf,0,buf.Length)) > 0)
         {
             out1.Write(buf, 0, ReadBytes);
         }
         return out1.ToArray();
     }
     catch (IOException e)
     {
         log.Log(POILogger.INFO, "Possibly corrupt compression or non-compressed data", e);
         return data;
     }
 }
		/// <summary>
		/// The decompression routine.
		/// </summary>
		/// <param name="bytes">The bytes to decompress.</param>
		/// <returns>A decompressed array of bytes.</returns>
		private static byte[] Decompress(byte[] bytes)
		{
			using (var byteStream = new MemoryStream(bytes))
			{
				using (Stream stream = new InflaterInputStream(byteStream))
				{
					using (var memory = new MemoryStream(Buffersize))
					{
						var buffer = new byte[Buffersize];
						while (true)
						{
							var size = stream.Read(buffer, 0, Buffersize);
							if (size <= 0)
							{
								break;
							}

							memory.Write(buffer, 0, size);
						}

						return memory.ToArray();
					}
				}
			}
		}