Read from stream splitted ZIp

Dec 11, 2009 at 11:32 AM

Good day folks,

I would need to know - if i can read from stream splitted number of Zip`s.

Lets say this code would return me some Stream with byte array, which contain "N" files in bytes[]

 using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
                FileStream zipFIle=File.OpenRead(@"C:\somefile.pdf");
                zip.AddEntry("somefile.pdf", zipFIle);

                zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
                zip.MaxOutputSegmentSize = 400000; 

                Stream outStr = new MemoryStream();


how can i read the out stream and understand where is which file?

Thanks for any help!

Dec 11, 2009 at 5:18 PM

No, you cannot do that.

The MaxOutputSegmentSize is respected only when you save to a filesystem file.   The doc says this:  "You can save a split Zip file only when saving to a regular filesystem file. It's not possible to save a split zip file as a self-extracting archive, nor is it possible to save a split zip file to a stream. When saving to a SFX or to a Stream, this property is ignored." 

What do you REALLY want to do?  What's the goal?

Dec 12, 2009 at 4:11 PM

Thats very  a shame. The goal is to split some file (read from BLOB db field) to several splitted archives without saving it to File System.

Is there any way to change the source code, to reach the target? Let say the Save() function would return collection of byte arrays or some objects collection?

Dec 12, 2009 at 5:01 PM

I don't understand the goal.  Why split the zip archive if it is not being transmitted in parts? 

The splitting was originally interesting, years ago, because ZIP files didn't "fit" into a single 1.44MB floppy drive.  At this point, splitting is still interesting because people have limits on how much data they can send in an email, or in other transmission mechanisms.  In all cases, a filesystem file is used as the unit of transport.

In your case, I don't understand why  you need zip splitting.  If you're not using a filesystem file, then why split it?

Can you explain in more detail what you are trying to do?


Dec 13, 2009 at 9:21 PM

I send files via mail. Customer has mail size limit.

I read files from DB.

It means:

1. I have to get file from DB.

2. Generate several mails with splitted zip parts.

I dont want to use file system. Have to do it online (in memory). Got me?

Dec 13, 2009 at 9:24 PM
Edited Dec 13, 2009 at 9:41 PM

Ok, thanks, now I understand.  As the library is today, You need to use the filesystem to do what you want. You can then load it into the DB from the filesystem.

If you are sending them in email as files, then I don't know why you wouldn't use the filesystem to store the files, but I suppose you have your reasons.  Most databases have the ability to reference filesystem files.

If you absolutely need to store them as blobs in the db, then you'll need to create the zip in the filesystem temporarily, before loading it into the db as you prefer.

Good luck.