public static byte[] Compress(object source) { try { XmlSerializer xmlSerializer = new XmlSerializer(source.GetType()); MemoryStream memoryStream = new MemoryStream(); xmlSerializer.Serialize((Stream)memoryStream, source); byte[] source1 = memoryStream.ToArray(); memoryStream.Close(); int length = source1.Length; int destLength = source1.Length + 1; byte[] dest = new byte[destLength]; if (ZLib.compress2(dest, ref destLength, source1, source1.Length, ZLib.ZLibCompressionLevel.Z_BEST_COMPRESSION) != ZLib.ZLibError.Z_OK) { return(new byte[0]); } byte[] numArray = new byte[destLength + 4]; Array.Copy((Array)dest, 0, (Array)numArray, 4, destLength); numArray[0] = (byte)length; numArray[1] = (byte)(length >> 8); numArray[2] = (byte)(length >> 16); numArray[3] = (byte)(length >> 24); return(numArray); } catch (Exception ex) { return(new byte[0]); } }
public static object Decompress(byte[] data, Type type) { object obj; try { int num = data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24; byte[] numArray = new byte[(int)data.Length - 4]; Array.Copy(data, 4, numArray, 0, (int)data.Length - 4); byte[] numArray1 = new byte[num]; if (ZLib.uncompress(numArray1, ref num, numArray, (int)numArray.Length) == ZLib.ZLibError.Z_OK) { MemoryStream memoryStream = new MemoryStream(numArray1); object obj1 = (new XmlSerializer(type)).Deserialize(memoryStream); memoryStream.Close(); obj = obj1; } else { obj = null; } } catch { obj = null; } return(obj); }
public static byte[] Compress(object source) { byte[] numArray; try { XmlSerializer xmlSerializer = new XmlSerializer(source.GetType()); MemoryStream memoryStream = new MemoryStream(); xmlSerializer.Serialize(memoryStream, source); byte[] array = memoryStream.ToArray(); memoryStream.Close(); int length = (int)array.Length; int num = (int)array.Length + 1; byte[] numArray1 = new byte[num]; if (ZLib.compress2(numArray1, ref num, array, (int)array.Length, ZLib.ZLibCompressionLevel.Z_BEST_COMPRESSION) == ZLib.ZLibError.Z_OK) { byte[] numArray2 = new byte[num + 4]; Array.Copy(numArray1, 0, numArray2, 4, num); numArray2[0] = (byte)length; numArray2[1] = (byte)(length >> 8); numArray2[2] = (byte)(length >> 16); numArray2[3] = (byte)(length >> 24); numArray = numArray2; } else { numArray = new byte[0]; } } catch (Exception exception) { numArray = new byte[0]; } return(numArray); }
public static bool CheckVersion() { string[] strArray; try { strArray = ZLib.zlibVersion().Split('.'); } catch (DllNotFoundException ex) { return(false); } return(strArray[0] == "1"); }
public static byte[] Decompress(byte[] data) { int destLen = (int)data[0] | (int)data[1] << 8 | (int)data[2] << 16 | (int)data[3] << 24; byte[] source = new byte[data.Length - 4]; Array.Copy((Array)data, 4, (Array)source, 0, data.Length - 4); byte[] dest = new byte[destLen]; if (ZLib.uncompress(dest, ref destLen, source, source.Length) != ZLib.ZLibError.Z_OK) { return((byte[])null); } return(dest); }
public static byte[] Decompress(byte[] data) { int num = data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24; byte[] numArray = new byte[(int)data.Length - 4]; Array.Copy(data, 4, numArray, 0, (int)data.Length - 4); byte[] numArray1 = new byte[num]; if (ZLib.uncompress(numArray1, ref num, numArray, (int)numArray.Length) != ZLib.ZLibError.Z_OK) { return(null); } return(numArray1); }
public static bool CheckVersion() { bool flag; string[] strArrays = null; try { strArrays = ZLib.zlibVersion().Split(new char[] { '.' }); return(strArrays[0] == "1"); } catch (DllNotFoundException dllNotFoundException) { flag = false; } return(flag); }
public static byte[] Compress(byte[] data) { int length1 = data.Length; int length2 = data.Length; byte[] dest = new byte[data.Length]; if (ZLib.compress(dest, ref length2, data, data.Length) != ZLib.ZLibError.Z_OK) { return((byte[])null); } byte[] numArray = new byte[length2 + 4]; Array.Copy((Array)dest, 0, (Array)numArray, 4, length2); numArray[0] = (byte)(length1 & (int)byte.MaxValue); numArray[1] = (byte)(length1 >> 8 & (int)byte.MaxValue); numArray[2] = (byte)(length1 >> 16 & (int)byte.MaxValue); numArray[3] = (byte)(length1 >> 24 & (int)byte.MaxValue); return(numArray); }
public static byte[] Compress(byte[] data) { int length = (int)data.Length; int num = (int)data.Length; byte[] numArray = new byte[(int)data.Length]; if (ZLib.compress(numArray, ref num, data, (int)data.Length) != ZLib.ZLibError.Z_OK) { return(null); } byte[] numArray1 = new byte[num + 4]; Array.Copy(numArray, 0, numArray1, 4, num); numArray1[0] = (byte)(length & 255); numArray1[1] = (byte)(length >> 8 & 255); numArray1[2] = (byte)(length >> 16 & 255); numArray1[3] = (byte)(length >> 24 & 255); return(numArray1); }
public static object Decompress(byte[] data, Type type) { try { int destLen = (int)data[0] | (int)data[1] << 8 | (int)data[2] << 16 | (int)data[3] << 24; byte[] source = new byte[data.Length - 4]; Array.Copy((Array)data, 4, (Array)source, 0, data.Length - 4); byte[] numArray = new byte[destLen]; if (ZLib.uncompress(numArray, ref destLen, source, source.Length) != ZLib.ZLibError.Z_OK) { return((object)null); } MemoryStream memoryStream = new MemoryStream(numArray); object obj = new XmlSerializer(type).Deserialize((Stream)memoryStream); memoryStream.Close(); return(obj); } catch { return((object)null); } }
public static TransferMessage Decompress(byte[] data, Type type) { return(ZLib.Decompress(data, type) as TransferMessage); }
public virtual byte[] Compress() { return(ZLib.Compress((object)this)); }