View Single Post
Old 27-09-2007, 02:29 PM   #6
Peter Duniho
Guest
 
Posts: n/a
Re: Zip file using a stream

And one more thing...

Chris Fink wrote:
> [...]
> byte[] buffer = new byte[4096];
> foreach (string file in filenames)
> {
> ZipEntry entry = new ZipEntry(file);
> entry.DateTime = DateTime.Now;
> s.PutNextEntry(entry);
> // TODO: last file is not added as entry
> byte[] ba = GetBlob(13);
> s.Write(ba, 0, ba.Length);
> }


This part seems okay, at least without knowing anything specific about
the class, and keeping in mind the possibility that you need to call
some sort of flush method.

But this part confuses me:

> // TODO: write stream to BLOB
> //...But before I try that test that the zip is valid by
> writting the ZipOutputStream
> // to disk
> using (FileStream fs = File.OpenRead(zipFileName))
> {
> int sourceBytes;
> do
> {
> sourceBytes = fs.Read(buffer, 0, buffer.Length);
> s.Write(buffer, 0, sourceBytes);
> } while (sourceBytes > 0);
> }


What exactly are you trying to do here? What is the contents of the
"test.zip" file? What is the point of appending those contents to your
ZipOutputStream? And why does it make sense to append those contents to
the last ZipEntry in the ZipOutputStream?

From your description, I expected to see some code _outside_ the "using
(ZipOutputStream...)" block that wrote the MemoryStream to the
"zipFileName" file, so that you could verify the stream as a valid ZIP
file using some independent tool (like Windows' built-in ZIP file
support). But instead, I see the opposite.

Not only was I surprised not to see what I expected, I'm not really
clear on what the code I do see is supposed to accomplish. It seems,
well...a little random to me.

Pete
  Reply With Quote