I tried the call to flush() with no difference. The last item is still not
being added to the list.
> > 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);
> > s.Flush()
> > }
I agree the code is a bit confusing. My objective is to read a byte array,
which represents one file, from from the database BLOB field; which is
working fine...then add each one to a zip file (ultimately in memory so I can
insert the zip file as a byte[] back to the blob field). However, for
testing reasons instead of doing the insert I am trying to write the zip file
to disk, which all this code is doing is creating an empty zip container.
So what i need help with is
1. figuring out why the last item is not added to the list
2. most importantly, why the zip file that is written to disk is empty.
Sorry for the confusion.
"Peter Duniho" wrote:
> 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
>