VB6 - Zipper & ZipWriter, Zipping from VB programs-VBForums
Results 1 to 4 of 4

Thread: VB6 - Zipper & ZipWriter, Zipping from VB programs

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,738

    Lightbulb VB6 - Zipper & ZipWriter, Zipping from VB programs

    Background

    A lot of us find the need to create ZIP archives programmatically from time to time. There are a number of techniques we can use, from spawning external utility programs to 3rd party components to Shell automation.

    Here is yet another way to accomplish this: using the free, open source zlibwapi.dll


    Minizip

    In addition to providing a STDCALL version of ZLib that we can call easily from VB6 programs zlibwapi.dll includes the Minizip project code as well.

    Like a lot of open source hacked out by C coders this can be rough in many places, but it is widely used and well proven. It should have few if any bugs in the most recent version.

    I'm using version 1.25 here. You can get this from:

    Minizip: Zip and UnZip additionnal library

    See the typo there? This is just one symptom of some of the issues, but fortunately the code at least seems to work fine even if its source is wonky with lots of flaws in comments and general documentation issues.

    This DLL is not included in the attachment. You must download it yourself.

    In zlib125dll.zip there is the Win32 Windows DLL of my Windows DLL named Zlibwapi.dll that contains both zLib and Minilib.
    The file you want from this ZIP archive is:

    zlib125dll.zip\dll32\zlibwapi.dll


    ZipWriter

    ZipWriter is a VB6 Class that wraps zlibwapi.dll to provide you with a way to create a ZIP archive and actually write data into it as archived files with no intermediate disk I/O steps.

    You can use this as-is in many cases without the other code offered here.


    Zipper

    Zipper is a VB6 UserControl that wraps ZipWriter and a small helper ZipFile Class to give you the ability to create a ZIP archive (or add to an existing one) and add a list of disk files to it.

    Zipper.Zip is an async operation and reports back progress, errors, and completion through several events. There is a Zipper.Cancel method if you need that.


    ZipDemo

    ZipDemo is a VB6 project that demonstrates use of the items described above.

    You must download zlibwapi.dll and copy it into this project folder to run the program.

    Much of the bulk of this attachment consists of the sample files in the "samples2" folder included.


    There is a "ZipWriter" button that does a simple test of ZipWriter, creating a new ZIP archive "test.zip" with two files written to it. When that step completes the "Zipper" button is enabled.

    The "Zipper" button tests Zipper, adding the files it finds in the "samples2" folder to the "test.zip" created in the first stage of the demo. While running a progressbar is updated and a "Cancel" button is enabled.

    The "samples2" folder as supplied has just a few small files. Be sure to copy some larger files into it and rerun the program to see how things go with large files. The performance is fairly good.


    Remarks

    While you need to deploy zlibwapi.dll with your programs this is a standard DLL that you can feel free to place next to your EXE. No registration is required.

    The results are better than those achieved using most other common techniques. Progress/Cancel/Complete can be really nice to have. There is no need for the shaky, convoluted, hackish window spelunking people often resort to when automating Shell objects.

    There is a lot more you can do with zlibwapi.dll too. You can read from ZIP archives, unzip them, compress separate files outside of ZIP archives, compress/expand data in memory, etc. Even the huge-file Zip64 format is supported.

    All you need is to write additional wrappers or just make the calls directly.
    Attached Files Attached Files

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,738

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Here is another demo. This one just shows creating a ZIP archive from a folder, but it also includes subfolders if any are present.

    That is something not spelled out in the previous example.


    Name:  sshot.png
Views: 45
Size:  5.5 KB

    Demo upon completion


    The sample data is included.
    Attached Files Attached Files

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,738

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    This is an update: Zipper 2 (version 2).

    This expands the ZipWriter class to handle password encryption of archived files, and the ability to specify the timestamp to be recorded in the archive for each file.

    The Zipper UserControl is expanded to accept file passwords and offers the option to use the disk file's LastUpdate timestamp instead of the result of the Now() function. This means Zipper has two helper classes now: ZipFile as before as well as the new ZipDateTimes. Nothing prevents the code in ZipDateTimes from being folded into Zipper itself, but keeping it separate helps keep Zipper at least a little easier to understand.


    Once again, the point of Zipper is to make it easy to ZIP up one or more files asynchronously with progress updates and completion notification. The result is far cleaner than using hacks to try to detect when (and even if) a Shell32 ZIP process completes and completes properly.

    A further enhancement might be the option to use the ZIP64 format to allow you to automate archiving of huge files. Note that until Windows Vista there was no File Explorer (Shell32) support for ZIP64.
    Attached Files Attached Files

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    11,738

    Re: VB6 - Zipper & ZipWriter, Zipping from VB programs

    Version 2.1, which adds ZipperSync.

    ZipperSync is a synchronous "clone" (very close copy) of the Zipper UserControl. ZipperSync may be a little easier to read because it doesn't have to use a time-slicing Timer to drive the I/O and processing.

    If your files to ZIP up into an archive are fairly small so that you do not need async operation to remain responsive you might choose ZipperSync instead of Zipper.

    The demo is very similar to the Zipper 2 Demo above.


    Edit:

    While hilarious if nobody had already downloaded it (not so funny since several people had), the attachment was a bit of a mess. It had a broken version of the new ZipperSync and was still using the Zipper control.

    Attachment replaced. Sorry for the error.
    Attached Files Attached Files
    Last edited by dilettante; Yesterday at 03:01 PM. Reason: replaced attachment

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.