示例#1
0
 public static byte ReadCompressedID(byte[] compressed)
 {
     using (MemoryStream input = new MemoryStream(compressed))
     using (ZlibStream zin = new ZlibStream(input, CompressionMode.Decompress))
     {
         int val = zin.ReadByte();
         if (val < 0)
             throw new InvalidDataException();
         return (byte)val;
     }
 }
示例#2
0
 /// <summary>
 /// Decompresses the specified data.
 /// </summary>
 /// <param name="data">The compressed byte array.</param>
 /// <param name="pos">The starting position into the byte array.</param>
 /// <param name="Length">The number of compressed bytes to decompress.</param>
 /// <returns>An uncompressed byte array</returns>
 public static byte[] Decompress(byte[] data, int pos, int Length)
 {
     byte[] compressedData = new byte[Length];
     Array.Copy(data, pos + 50, compressedData, 0, Length);
     ZlibStream inflaterInputStream = new ZlibStream(new MemoryStream(compressedData),CompressionMode.Decompress);
     MemoryStream out1 = new MemoryStream();
     int c;
     try
     {
         while ((c = inflaterInputStream.ReadByte()) != -1)
             out1.WriteByte((byte)c);
         return out1.ToArray();
     }
     catch (IOException e)
     {
         throw new RecordFormatException(e.ToString());
     }
     finally
     {
         out1.Close();
         if (inflaterInputStream != null)
         {
             inflaterInputStream.Close();
         }
     }
 }