讨教个问题c#解压问题,本人在pb中压缩的。前4个字节存的文件原始长度+zlib 压缩的内容,合并后的在c#中怎么解压?
本人用的调用外部zlib.dll老报 -3错误
本人用的调用外部zlib.dll老报 -3错误
} [DllImport("ZLIB1.DLL", EntryPoint = "uncompress")] private static extern int uncompress(ref byte[] uncompr, ref uint uncomprlen, ref byte[] compr, uint lcomp); private int of_uncompress(ref object ob, int lx) { /// <summary>This is the important function that will perform the conversion</summary> uint ll_UncompressedLen, ll_UncompressLen = 0;int ll_Return; Byte[] lblb_Uncompressed, ablb_uncompress,b1,b2; ablb_uncompress = Serialize(ob); b1 = new byte[4]; b1=ablb_uncompress.Take(4).ToArray(); b2= ablb_uncompress.Skip(4).ToArray(); //ll_UncompressedLen = (int)Deserialize(b1); ll_UncompressedLen = 100000;// BitConverter.ToInt32(b1,0); //ablb_uncompress = blobmid(ablb_uncompress, 5); //ll_UncompressLen = len(ablb_uncompress); lblb_Uncompressed =new byte[ll_UncompressedLen]; ll_UncompressLen = 10000;// b2.Length; ll_Return = uncompress(ref lblb_Uncompressed, ref ll_UncompressedLen,ref b2, ll_UncompressLen ); ob = Deserialize(lblb_Uncompressed); return ll_Return; } ///<summary> /// 序列化 /// </summary> /// <param name="data">要序列化的对象</param> /// <returns>返回存放序列化后的数据缓冲区</returns> public static byte[] Serialize(object data) { BinaryFormatter formatter = new BinaryFormatter(); MemoryStream rems = new MemoryStream(); formatter.Serialize(rems, data); return rems.GetBuffer(); } /// <summary> /// 反序列化 /// </summary> /// <param name="data">数据缓冲区</param> /// <returns>对象</returns> public static object Deserialize(byte[] data) { BinaryFormatter formatter = new BinaryFormatter(); MemoryStream rems = new MemoryStream(data); data = null; //rems.Position = 0; //formatter.posi rems.Seek(0, SeekOrigin.Begin); return formatter.Deserialize(rems); }
解决方案
100
.net有zlib的,没必要调c的
http://www.componentace.com/zlib_.NET.htm
http://www.componentace.com/zlib_.NET.htm