471,344 Members | 1,556 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

Issues with SharpZipLib

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();
}
Jul 21 '05 #1
2 2515
I'm not sure, but I ran into a similar issue to this and I think you
need to check the return value from the s.Read call. It's possible
that it is not reading all the bytes from the zip stream. I think you
need to run it in a loop and keep reading until there is no more data
to read. I don't have the code I used at hand, but when I can find it
I'll post it.

Chris

Jul 21 '05 #2
Christer <wi******@hotmail.com> wrote:
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.
See http://www.pobox.com/~skeet/csharp/readbinary.html

Don't assume that Stream.Read will return as many bytes as you
requested from it in one go.
Furthermore, the filenames get corrupted when using special
characters.


That I'm not sure about - there may be a restriction in the zip format
itself.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by BeanDog | last post: by
1 post views Thread by Calvin Slater | last post: by
3 posts views Thread by phonious | last post: by
1 post views Thread by Brian Henry | last post: by
4 posts views Thread by Sam | last post: by
2 posts views Thread by Christer | last post: by
3 posts views Thread by CodeTalker | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.