zlib是一个用visual C++编写的应用程序,可在线使用。在c#中使用zlib压缩文件时解压文件
我有一个在visual studio C++应用程序中使用zlib压缩的文件。现在我正在尝试编写一个完全不同的c#程序来在visual c#应用程序中解压缩它。我所做的是:
我有一个包含3压缩(使用zlib的)文件(FFO,符号和CFF).fdd扩展大文件。
首先,我将整个.fdd文件转换为一个字节数组。
我找到了三个文件的确切位置。
使用循环,将文件的各个字节复制到另一个数组中。因此,在第一次迭代中,数组存储ffo字节,在第二次迭代中存储sym字节等。
将复制的字节数组转换为带.zip扩展名的文件,以便分离出3个压缩文件。
因此,我将文件命名为Fileffo.zip,Filesym.zip和Filecff.zip。
现在我需要解压文件并将解压文件命名为P.ffo,Q.sym和R.cff。
我只知道使用gzip实用工具压缩了.fdd文件。前四个字节包含ffo文件的大小,从第五个字节到ffo存在的大小(从前四个字节开始),在ffo之后,接下来的四个字节包含sym文件的大小,然后是sym文件,接下来的四个字节包含cff文件的大小,然后是cff文件本身。这就是为什么我试图从它们之前的相应四个字节中提取各个文件的大小。然后尝试通过循环将三个文件中的字节信息分别保存在数组中。
如何使用c#解压缩它们?当使用“zlib”压缩文件时,我不知道确切的扩展名,所以我放入了.zip扩展名。
public static void ExtractFile()
{
int i = 0;
const string zipPath = @"C:\Product Development\Development\FFPCAppTool\PCToolForFF\PCToolForFF\bin\x86\Debug\000A1C10000101.fdd";
if (zipPath.Contains("000A1C10000101.fdd"))
{
byte[] arrayWholeFileInBytes = File.ReadAllBytes(zipPath);
long fileLength = new FileInfo(zipPath).Length;
//string testpath = @"C:\Product Development\Development\ExtractedFdd\" + ManuId + "\\" + DeviceIdentifier + "\\" + Revision + ".zip";
const string testzippath = @"C:\Users\Himagau\Desktop\testExtract\Fileffo.zip";
const string extractPath = @"C:\Users\Himagau\Desktop\testExtract\ ";
while (i < fileLength)
{
using (BinaryReader reader = new BinaryReader(new FileStream(zipPath, FileMode.Open)))
{
reader.BaseStream.Seek(i, SeekOrigin.Begin);
reader.Read(arrayWholeFileInBytes, i, 4); //reading value in bytes
n = BitConverter.ToInt32(arrayWholeFileInBytes, i);
//converting first four bytes into a single integer value i.e. size of zip
reader.Read(arrayWholeFileInBytes, i + 4, n);
byte[] array1 = new byte[n]; //passing the size of zip into array size
Array.Copy(arrayWholeFileInBytes, i + 4, array1, 0, n);
File.WriteAllBytes(testzippath, array1);
ZipFile.ExtractToDirectory(testzippath, extractPath);
i = i + n + 4;
}
}
}
}
zip文件& zip压缩包是给了这样的错误central directory not found
当改变文件的扩展名从.zip文件。广州则gzipstream是给错误的“不是一个有效的gzip文件。”
我在'extractPath'的值中增加了一个空格,这样本网站的着色就不会被吓倒了。只是要知道。 – gunr2171 2014-10-31 20:17:56
你看过[GZipStream](http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream(v = vs.110).aspx) – 2014-10-31 23:24:51