Zipping

deloreandude

New member
Joined
Sep 21, 2008
Messages
4
Programming Experience
3-5
Hi

Im having a problem and wondered if anyone could offer a sollution.

Im trying to use VB.net to merge 2 zip files. Namly add any new files in and replace existing from one file to another.

Ive tried this using sharpziplib to no avail. There are plenty of examples showing how to put a memorystream into a zip file but none on how to add to an existing zip file from a memory stream. I was wanting to open both files and then read from one as a stream and then write the stream straight into the other file.

Can anyone help. Im happy to use another library if it solves the issue.

thanks
 
hi

do you tried using dotnetzip? i have worked with this library. it's easy to use.

DotNetZip Library
I just tried this library as well, and liked it a lot. Very similar to SharpZipLib, but some more features and even easier to use I think, better documentation with VB.Net code samples also.

Here is a sample that updates/adds all entries from source.zip to target.zip:
VB.NET:
Using source As New ZipFile("source.zip"), target As New ZipFile("target.zip")
    For Each sourceEntry In source
        Using mem As New IO.MemoryStream(CInt(sourceEntry.UncompressedSize))
            sourceEntry.Extract(mem)
            target.UpdateEntry(sourceEntry.FileName, mem.ToArray)
        End Using
    Next
    target.Save()
End Using
UpdateEntry method is a shortcut for deleting the target entry if it exist, then adding new one with same name. (this is something I found difficult doing with SharpZipLib)

Note, if you're working with very large content files you could extract those to temp file in file system instead. Since DotNetZip/Ionic uses delayed read/write for stream sources when Save is called it is also possible to manage this by using AddEntry method with a WriteDelegate where you copy the sources from ZipEntry.OpenReader stream.
 
Hi again

Thanks for the information. Now looking into DotNetZip as it seems to be more geared towards what we need.

Can you further explain what you said

"Since DotNetZip/Ionic uses delayed read/write for stream sources when Save is called it is also possible to manage this by using AddEntry method with a WriteDelegate where you copy the sources from ZipEntry.OpenReader stream. "

You lost me a little here.
Thanks
 
Can you further explain what you said

"Since DotNetZip/Ionic uses delayed read/write for stream sources when Save is called it is also possible to manage this by using AddEntry method with a WriteDelegate where you copy the sources from ZipEntry.OpenReader stream. "

You lost me a little here.
Thanks
It is just one of the alternatives for creating entries, documentation explains that when the entrys data source is a stream that stream must be open for reading when Save is called. So to avoid many open read streams you can delegate the stream transfer to a method that is called for each stream based entry when Save is called. It will come clear to you if you read the documentation. The example above uses byte array source and not a stream source.
 
Back
Top