Tag: zlib

无法解压缩ZLIB / DEFLATE数据

我正在尝试从网络捕获文件(PCAP)中提取压缩字节数据。 来自其中一些数据包的数据没有ZLIB标头(前2个字节,其中第一个字节的低4位始终为8),因此当我尝试使用ZlibStream进行解压缩时会出现ZlibStream 。 标题数据似乎工作正常。 据我所知,ZLIB只是DEFLATE的页眉和页脚,我将没有标题的数据传递给DeflateStream 。 这次DeflateStream不会抛出任何错误,它只是提供了错误的数据(但它给出了正确的长度)…… 这是一个示例数据。 C#代码示例使用DotNetZip: byte[] test3 = new byte[] { 0x1a, 0x6d, 0xf, 0x8d, 0xb6, 0x87, 0x46, 0xdb, 0x43, 0xa3, 0xed, 0xa1, 0xd1, 0xf6, 0xd0, 0x68, 0x7b, 0x68, 0xb4, 0x3d, 0x34, 0xda, 0x1e, 0xb2, 0x44, 0x3a, 0x39, 0x6f, 0x24, 0xae, 0x1f, 0x2, 0x0, 0x0, 0x0, 0xff, 0xff }; static void […]

从C ++到C#的zlib(如何将byte 转换为流并将流转换为byte )

我的任务是使用zlib解压缩数据包(已接收),然后使用算法从数据中生成图片 好消息是我有C ++代码,但任务是在C#中完成 C ++ //Read the first values of the packet received DWORD image[200 * 64] = {0}; //used for algoritm(width always = 200 and height always == 64) int imgIndex = 0; //used for algoritm unsigned char rawbytes_[131072] = {0}; //read below unsigned char * rawbytes = rawbytes_; //destrination parameter for decompression(ptr) compressed […]

如何使用zlib.NET扩展文件?

我正在使用zlib.NET库来尝试和扩充由zlib压缩的文件(可能在Linux机器上)。 这就是我正在做的事情: zlib.ZInputStream zinput = new zlib.ZInputStream(File.Open(path, FileMode.Open, FileAccess.Read)); while (stopByte != (data = zinput.ReadByte())) { // check data here } zinput.Close(); 数据字节与压缩数据字节匹配,因此我必须做错事。

zlib压缩字节数组?

我有这个未压缩的字节数组: 0E 7C BD 03 6E 65 67 6C 65 63 74 00 00 00 00 00 00 00 00 00 42 52 00 00 01 02 01 00 BB 14 8D 37 0A 00 00 01 00 00 00 00 05 E9 05 E9 00 00 00 00 00 00 00 00 00 00 […]

从C#NET 3.5中的byte 保存文件

我的TCP客户端在数据包中接收图像。图像使用zlib压缩。任务是解压缩图像并将其放在表单上。 我打算将压缩的图像保存在当前目录中,解压缩并在表单上加载解压缩的文件。 第一个问题是保存文件(压缩).zlib可以保存解压缩。 下面的代码加载压缩文件并在解压缩后保存。 private void decompressFile(string inFile, string outFile) { System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create); zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outFileStream); System.IO.FileStream inFileStream = new System.IO.FileStream(inFile, System.IO.FileMode.Open); try { CopyStream(inFileStream, outZStream); } finally { outZStream.Close(); outFileStream.Close(); inFileStream.Close(); } } public static void CopyStream(System.IO.Stream input, System.IO.Stream output) { byte[] buffer = new byte[2000]; int len; […]

有没有办法用另一个库解压缩DynaZip Max文件? FE DotNetZip

我有一个数据库,我们使用以下代码存储使用DynaZip Max Secure压缩的pdf文件: MemoryStream msIN = new System.IO.MemoryStream(); //Input MemoryStream MemoryStream msZip = new System.IO.MemoryStream(); //Compressed MemoryStream BinaryReader objBinaryReader; BinaryWriter objBinaryWriter; public MemoryStream CompressStream(byte[] vbuf) { System.IO.BinaryWriter bw = new System.IO.BinaryWriter(msIN); bw.Write(vbuf); CDZipSNET dz1 = new CDZipSNET(); dz1.ZipMemToMemCallback += new CDZipSNET.OnZipMemToMemCallback(this.ZipMemToMemCallback_event); dz1.ActionDZ = CDZipSNET.DZACTION.ZIP_MEMTOMEM; return msZip; } 这是ZipMemToMemCallback_event代码: public void ZipMemToMemCallback_event(CDZipSNET.MEMTOMEMACTION lAction,ref byte[] lpMemBuf,ref uint […]

zlib.Net的压缩和解压缩问题

我正在使用ZLIB.Net ,我只是不明白我该怎么做才能压缩不是FileStream的流,而是压缩MemoryStream 。 通过做: byte[] buffer = ASCIIEncoding.ASCII.GetBytes(“Hello World”); MemoryStream outStream = new MemoryStream(); zlib.ZOutputStream outZStream = new zlib.ZOutputStream( outStream, zlib.zlibConst.Z_BEST_COMPRESSION); outZStream.Write(buffer, 0, buffer.Length); outZStream.finish(); buffer = outStream.GetBuffer(); Debug.WriteLine(DateTime.Now.ToString() + “:” + buffer.Length); MemoryStream inStream = new MemoryStream(buffer); MemoryStream mo = new MemoryStream(); zlib.ZInputStream inZStream = new zlib.ZInputStream( inStream, zlib.zlibConst.Z_BEST_COMPRESSION); int n = 0; while […]

Zlib兼容的压缩流?

System.IO.Compression.GZipStream或System.IO.Compression.Deflate与zlib压缩兼容吗?

.Net zlib使用.Net 4.5进行扩充

根据MSDN的.Net 4.5 System.IO.Compression基于zlib。 我现在正在尝试将当前基于互操作的读取从非.NET服务器中的zlib放气流更改为基于BCL的实现。 我的实现看起来像这样: var enc = new UTF8Encoding(); var readBytes = BufferSizeRaw; var outputBuffer = new byte[BufferSizeRaw]; var networkBuffer = _networkQueue.Take(); var ms = new MemoryStream(networkBuffer.InputBuffer, 0, networkBuffer.UsedLength); using (Stream stream = new DeflateStream(ms, CompressionMode.Decompress)) while (readBytes==BufferSizeRaw) { readBytes = stream.Read(outputBuffer, 0, outputBuffer.Length); stringBuffer+= enc.GetString(outputBuffer, 0, readBytes); } 我在DeflateStream上第一次调用解压缩/读取时收到以下exception: 块长度与其补码不匹配 基于互操作的调用使用var result=inflate(ref zStyream, […]