Results 1 to 3 of 3

Thread: how to zip files in vb?

  1. #1
    Guest
    E-mail me at [email protected] and I'll send you some ZIP Libraries.

  2. #2

    Wink Zlib and Info-Zip: The best zip/unzip for any platform

    Zlib and Info-Zip resources are the key, and are free, even for commercial use. HeSaidJoe's URL deals with Info-Zip. The internet is littered with sites that want to charge you for black-box OCX’s that purportedly provide zip capability to VB; ignore them all. The best is free.

    The basic difference between Info-Zip’s dll’s (zip32.dll, unzip32.dll) and Zlib.dll is this. Info-Zip’s dll’s create and upzip FILES, whereas Zlib.dll zips and unzips Byte arrays and strings.

    Recent VB encapsulation of Info-Zip's dll's is at:
    http://www.vbaccelerator.com/codelib/zip/zipvb.htm
    http://www.vbaccelerator.com/codelib/zip/zip.htm
    http://www.vbaccelerator.com/codelib/zip/unzip.htm
    http://codeguru.earthweb.com/vb/articles/1854.shtml

    Recent VB6 encapsulation of Zlib is at: http://www.vbaccelerator.com/codelib/zip/zlib.htm (This is for 32-bit VB 6.0)

    The basic Info-Zip sites are:
    ftp://ftp.info-zip.org/pub/infozip/info-zip.html . (Not necessarily as current are
    http://www.info-zip.org/pub/infozip and http://www.freesoftware.com/pub/infozip/)
    ftp://ftp.info-zip.org/pub/infozip (same as ftp://ftp.freesoftware.com/pub/infozip)
    The files zip23dn.zip unz541dn.zip on ftp://ftp.info-zip.org/pub/infozip/WIN32/ contain the .dll’s and VB encapsulations.

    The basic Zlib sites are:
    ftp://ftp.freesoftware.com/pub/infozip/zlib/index.html
    ftp://ftp.freesoftware.com/pub/infozip/zlib/ (The VB encapsulation cited here is for VB 5 (16-bits, I think) It is superceded by that at http://www.vbaccelerator.com/codelib/zip/zlib.htm)

    I believe that the easiest way to incorporate efficient zip/unzip capability is as follows. First copy zlib.dll to C:\Windows\System, or whatever the system directory is. Then, in module-level declarations (sorry, I wasn't successful in getting <code></code> to preserve indentation):

    Public Declare Function uncompress Lib "zlib.dll" (dest As Any, destLen As Any, src As Any, ByVal srcLen As Long) As Long

    Public Declare Function compress Lib "zlib.dll" (dest As Any, destLen As Any, src As Any, ByVal srcLen As Long) As Long

    Public Const ZLIB_NOERROR = 0

    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

    Public ErrorCode&

    Then I use the following subroutines:

    Sub ZipBytes(Bytes() As Byte, OrigSize&, ZipSize&, FileNo&)
    Dim TempBuffer() As Byte
    ' Ensure we have sufficient space for the worst possible case (no compression
    ' plus additional space for the compression info) according Zlib author specifications:
    ZipSize = OrigSize + (OrigSize * 0.01) + 12
    ReDim TempBuffer(0 To ZipSize - 1) As Byte
    ErrorCode = compress(TempBuffer(0), ZipSize, Bytes(0), OrigSize)
    If ErrorCode = 0 Then 'ZLIB_NOERROR = 0
    If ZipSize > 0 Then
    ReDim Preserve Bytes(0 To ZipSize - 1) As Byte 'Preserve might be faster than zeroing.
    CopyMemory Bytes(0), TempBuffer(0), ZipSize 'But it all gets written over by this API call anyway.
    Else
    Erase Bytes
    End If
    Else
    MsgBox "Error in zipping " & OutputBookFiles(FileNo).DisplayName & ". Zlib error code = " & CStr(ErrorCode)
    End If

    Sub UnZipBytes(ByRef InputBytes() As Byte, StartPtr&, ZipSize&, OrigSize&, OutputBytes() As Byte)
    Dim ErrorCode&, StartSize&
    StartSize = OrigSize
    ReDim OutputBytes(0 To StartSize) As Byte
    StartSize = StartSize + 1
    'Decompress data: OutputBytes and StartSize were deliberately oversized by one (reasons unknown)
    'but uncompress knocks it back to it input value in all known cases. If ain't broke -- and it ain't -- don't fix it!
    ErrorCode = uncompress(OutputBytes(0), StartSize, InputBytes(StartPtr), ZipSize)
    If ErrorCode = ZLIB_NOERROR Then
    If StartSize = OrigSize Then
    ReDim Preserve OutputBytes(0 To StartSize - 1) As Byte 'Preserve might be faster than zeroing.
    Else
    MsgBox "Error in unzipping " & FileName(0) & ". Unzipped file size not the same as the original."
    Call Cleanup ‘Change as appropriate for your application.
    End If
    Else
    MsgBox "Error in unzipping " & FileName(0) & ". Zlib error code = " & CStr(ErrorCode)
    Call Cleanup 'Change for your application.
    End If
    End Sub

  3. #3
    Hyperactive Member Juan Carlos Rey's Avatar
    Join Date
    Aug 1999
    Location
    Mendoza, Argentina
    Posts
    301
    What´s wrong in using pkzip/pkunzip?

    ------
    Call Shell("pkzip myfile.zip", vbHide)
    ------

    See http://forums.vb-world.net/showthrea...threadid=30161
    for more details




    Combat poverty: kill a poor!!

Posting Permissions

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



Click Here to Expand Forum to Full Width