C
Christer
Hi all,
I've been trying to use the SharpZipLib as it sounds promising and a
lot of people refer to it in discussions on compression. However, I am
getting some bad output, when I try to unzip a (correctly hand made)
..zip file via code. I DO get the right amount of files, however, some
seem cut in half ... when viewing the output files directly, some of
the .gif file show only half, some of the included .swf files show
nothing.
Furthermore, the filenames get corrupted when using special
characters.
Could someone with experience in using the SharpZipLib, please give me
a view on my troubles? Extraction code below...
Kind regards,
Christer
string rootPath = @"c:\sletmig\";
FlushExtractDir(); //Delete existing output directory
ZipFile zFile = new ZipFile(rootPath + "vejledning.zip");
try
{
//For each entry in zip file...
foreach (ZipEntry e in zFile)
{
string fileName = Path.GetFileName(rootPath + @"udpak\" + e.Name);
string directoryName = Path.GetDirectoryName(rootPath + @"udpak\" +
e.Name);
//Ensure directory...
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
//If file entry, create the file...
if (fileName.Length > 0)
{
System.IO.Stream s = zFile.GetInputStream(e);
int length = (int)e.Size;
byte[] bytes = new byte[length];
s.Read(bytes, 0, length);
FileStream newfile = new FileStream(rootPath + @"udpak\" + e.Name,
FileMode.Create);
newfile.Write(bytes, 0, length);
newfile.Close();
s = null;
}
}
}
finally
{
zFile.Close();
}
I've been trying to use the SharpZipLib as it sounds promising and a
lot of people refer to it in discussions on compression. However, I am
getting some bad output, when I try to unzip a (correctly hand made)
..zip file via code. I DO get the right amount of files, however, some
seem cut in half ... when viewing the output files directly, some of
the .gif file show only half, some of the included .swf files show
nothing.
Furthermore, the filenames get corrupted when using special
characters.
Could someone with experience in using the SharpZipLib, please give me
a view on my troubles? Extraction code below...
Kind regards,
Christer
string rootPath = @"c:\sletmig\";
FlushExtractDir(); //Delete existing output directory
ZipFile zFile = new ZipFile(rootPath + "vejledning.zip");
try
{
//For each entry in zip file...
foreach (ZipEntry e in zFile)
{
string fileName = Path.GetFileName(rootPath + @"udpak\" + e.Name);
string directoryName = Path.GetDirectoryName(rootPath + @"udpak\" +
e.Name);
//Ensure directory...
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
//If file entry, create the file...
if (fileName.Length > 0)
{
System.IO.Stream s = zFile.GetInputStream(e);
int length = (int)e.Size;
byte[] bytes = new byte[length];
s.Read(bytes, 0, length);
FileStream newfile = new FileStream(rootPath + @"udpak\" + e.Name,
FileMode.Create);
newfile.Write(bytes, 0, length);
newfile.Close();
s = null;
}
}
}
finally
{
zFile.Close();
}