gpt4 book ai didi

c# - 有没有办法用另一个库解压缩 DynaZip Max 文件? F.E. DotNetZip

转载 作者:太空狗 更新时间:2023-10-29 21:18:10 25 4
gpt4 key购买 nike

我有一个数据库,我们使用以下代码存储了使用 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 pdwSize,uint dwTotalReadL,uint dwTotalReadH,uint dwTotalWrittenL,uint dwTotalWrittenH,ref CDZipSNET.MEMTOMEMRESPONSE plRet)
{
int bytesToRead;

switch(lAction)
{
case CDZipSNET.MEMTOMEMACTION.MEM_READ_DATA:
if((dwTotalReadL == 0) && (dwTotalReadH == 0))
{
msIN.Seek(0, System.IO.SeekOrigin.Begin);
objBinaryReader = new System.IO.BinaryReader(msIN);
}
try
{
bytesToRead = (int)(objBinaryReader.BaseStream.Length - dwTotalReadL);
if(bytesToRead > pdwSize)
{
bytesToRead = (int)pdwSize;
plRet = CDZipSNET.MEMTOMEMRESPONSE.MEM_CONTINUE;
}
else
{
plRet = CDZipSNET.MEMTOMEMRESPONSE.MEM_DONE;
}
pdwSize = (uint)bytesToRead;
if(bytesToRead > 0)
{
objBinaryReader.Read(lpMemBuf, 0, bytesToRead);
}
}
catch
{
plRet = CDZipSNET.MEMTOMEMRESPONSE.MEM_ERROR;
}
break;

case CDZipSNET.MEMTOMEMACTION.MEM_WRITE_DATA:
if((dwTotalWrittenL == 0) && (dwTotalWrittenH == 0))
{
objBinaryWriter = new System.IO.BinaryWriter(msZip);
}
try
{
objBinaryWriter.Write(lpMemBuf, 0, (int)pdwSize);
plRet = CDZipSNET.MEMTOMEMRESPONSE.MEM_CONTINUE;
}
catch (System.Exception)
{
plRet = CDZipSNET.MEMTOMEMRESPONSE.MEM_ERROR;
}
break;

default: plRet = CDZipSNET.MEMTOMEMRESPONSE.MEM_ERROR;
break;
}
}

我会提供任何其他必要的东西来回答这个谜语,我试过常规的 Zip 解压缩、Zlib、Gzip 都无济于事。我将不胜感激任何帮助。谢谢。

编辑: 问题是 DinaZip 是一个专有的、已停产的库,发布它的公司没有提供任何帮助或故障排除,我受命解压缩以前压缩过的一堆文件使用这个库(使用代码 avobe),我不再有可用于解压的库,我想知道是否有人知道解压这个文件的任何方法,也许使用另一个库或方法。

最佳答案

此代码来自https://zlibnet.codeplex.com它可以解压缩未加密的 DynaZip 流:

public static class DynazipCompressor
{
const int DZ_DEFLATE_POS = 46;

public static bool IsDynazip(byte[] source)
{
return source.Length >= 4 && BitConverter.ToInt32(source, 0) == 0x02014b50;
}

public static byte[] DeCompress(byte[] source)
{
if (!IsDynazip(source))
throw new InvalidDataException("not dynazip header");
using (MemoryStream srcStream = new MemoryStream(source, DZ_DEFLATE_POS, source.Length - DZ_DEFLATE_POS))
using (MemoryStream dstStream = DeCompress(srcStream))
return dstStream.ToArray();
}

private static MemoryStream DeCompress(Stream source)
{
MemoryStream dest = new MemoryStream();
DeCompress(source, dest);
dest.Position = 0;
return dest;
}

private static void DeCompress(Stream source, Stream dest)
{
using (DeflateStream zsSource = new DeflateStream(source, CompressionMode.Decompress, true))
{
zsSource.CopyTo(dest);
}
}
}

DynaZip 流只是一个带有 PKZIP header 的 DeflateStream,所以这段代码只是跳过了 header 。

关于c# - 有没有办法用另一个库解压缩 DynaZip Max 文件? F.E. DotNetZip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15671968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com