error on larger files

Mar 25, 2009 at 6:17 PM
Edited Mar 25, 2009 at 7:04 PM
I'm working on a project that needs to use DotNetZip in "pure streaming mode" -- where both the input is a stream and the output is a stream (which is then ftp'ed). The code works fine for very small output, but even files only about 500K aren't readable as an xp or vista compressed folder. However, I know the end-to-end process works because the resulting output zip file (I've tested up to several megs) ARE readable by using DotNetZip to decompress them. Is there something basic I'm missing? I'm using version 1.7.2.12 of the library.

Here's the little class I created (a bit overkill, but I'll be adding more customization later):

class Zip : ZipFile

    {

 

        internal bool zipEncrypt(Stream inF, Stream outF, SubscriptionData subData, string fullFileName, ref StringBuilder m_sb)

        {

            using (ZipFile myZip = new ZipFile())

            {

                try

                {

                    if (subData.UseZipPassword)

                    {

                        myZip.Password = subData.ZipPassword;

                        myZip.Encryption = EncryptionAlgorithm.PkzipWeak;

                    }

                    else

                        myZip.Encryption = EncryptionAlgorithm.None;

 

                    myZip.CompressionLevel = Ionic.Zlib.CompressionLevel.BEST_COMPRESSION;

                    myZip.UseUnicodeAsNecessary = false;

                    myZip.UseZip64WhenSaving = Zip64Option.AsNecessary;

 

                    myZip.AddFileStream(fullFileName.Replace(".zip",""), "", inF);

                    myZip.Save(outF);

                }

                catch (Exception ex)

                {

                    throw ex;

                }

                return true;

            }

        }

    }

and here's how I'm calling it:

                        using (Zip myZip = new Zip())

 

                        {

                            try

                            {

                                using (MemoryStream encryptedStream = new MemoryStream())

                                {

                                    inStream.Position = 0;

                                    myZip.zipEncrypt(inStream, encryptedStream, data, fullFileName, ref m_sb);

                                    this.reportdata = encryptedStream.GetBuffer();

                                }

                                return true;

                            }

                            catch (Exception ex)

                            {

                               

                            }

                        }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Coordinator
Mar 25, 2009 at 7:03 PM

It should work the way you would like it to work.

I'm not completely clear on what works and what does not.
When  you say "the entire process works" - have you tried reading the "multi-meg" result in Windows XP Compressed folders? 

Is is the size that makes the difference ?  Or is it the streaming part?  Or both?
Are you saying that files above about 500k are not readable?
or files created with streaming, above 500k, are not readable? 
or...

I'll take a look at your code when I get a chance.

Mar 25, 2009 at 7:17 PM

sorry for being vague:

using the exact code above, if I zip a small stream (I don't know the exact size, but it represents a report based on a 10,000 row table), it is fully readable as a Windows compressed folder and reports is full size as 108K (compressed to 25K). If I rerun the same code reading a 100,000 row version of the same report, it is decompressible using the ZipEntry.Extract method, but can't be opened using built in Windows compressed folders or via WinZip. The output file appears to be compressed -- the uncompressed version of the file I create is about 1.2M while the unreadable zip file is 514K.

Coordinator
Mar 26, 2009 at 4:35 AM
ok I will have a look, see what I can figure out.
Coordinator
Mar 26, 2009 at 9:40 PM

I tried but was not able to reproduce this behavior you reported.

I have some concerns about your code, though.  The Zip class you have defined, derives from Ionic.ZipFile, I guess.  But it exposes a single method, zipEncrypt(), which creates a ZipFile, without ever using the base class. So I don't understand why you would derive your class from ZipFile?  In fact your Zip class defines no member variables or methods - and so the zipEncrypt() method can and probably should be defined as a static method. 

Also, the StringBuilder parameter to the zipEncrypt method is never used.
I also don't understand what you are doing with the code that removes the extension from the fullfilename.  (fullFilename.Replace(".zip", ""))
And that code suggests that you may be adding a zip file into a zip file, which... also doesn't make sense to me.  Why would you embed a zipfile into a zipfile?

Also, your code does not show how the output stream gets saved to a file, which I guess you would need to do, if you try to open it with WinZip.  
With all these questions, I'm not sure what to think. 

Can you produce a standalone test case, preferably a console app, that reliably reproduces the problem you've described?   and can you send me that code? 

 
 

Mar 28, 2009 at 7:38 AM
I had pulled out a lot of the code, so it had some things that looked unused.

It turned out to be my GetBuffer() call, when I read the now-zip-compressed data in the memorystream (this.reportdata = encryptedStream.GetBuffer();) it was somehow corrupting the data, although the finished file was the correct size. When I changed the .GetBuffer() to .ToArray() it worked fine.
Coordinator
Mar 28, 2009 at 8:24 AM
Glad you were able to figure it out!