Results 1 to 6 of 6

Thread: [2005] SharpZipLibrary Help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    22

    [2005] SharpZipLibrary Help

    I've found this: http://www.componentspot.com/doccenter/SharpZipLib/
    I've looked at what it supports and other things, but would anyone be so helpful to get me on the right tracks of extracting a file, it's for my Updater once again, everything is in PERFECT working order now, I just need to get the files in a ZIP file, delete them from the current directory and extract the ZIP ( or override the current files ). I'm stumped as how to do this though, where would I start?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] SharpZipLibrary Help

    I wrote a wrapper for #ZipLib many months ago in VB.NET 2003. I believe they've made some improvements since then but the old code may still work as is. If not it will at least give you a very good starting point to write your own code. Apparently some people had some issues extracting files under certain circumstances but I never did get around to looking at the issue. Like I said, it's a very good starting point if nothing else.

    http://www.vbforums.com/showthread.php?t=360169
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: [2005] SharpZipLibrary Help

    unzip using sharpziplib

    Code:
            
            dim extractDir as string = "c:\program files\unzip\"
    
            ' Using 
            Dim s As ZipInputStream = New ZipInputStream(File.OpenRead(zipfile path))
    
            Try
                Dim entry As ZipEntry = s.GetNextEntry
                While Not entry Is Nothing
    
                    Dim directoryName As String = Path.GetDirectoryName(extractDir & entry.Name)
    
                    Dim fileName As String = Path.GetFileName(extractDir & entry.Name)
                    If directoryName.Length > 0 Then
                        Directory.CreateDirectory(directoryName)
                    End If
                    If Not (fileName = String.Empty) Then
                        ' Using 
                        Dim streamWriter As FileStream = File.Create(extractDir & entry.Name)
                        Try
    
                            Dim size As Long = entry.Size
                            Dim data(size - 1) As Byte
                            Dim tgl As Boolean = True
    
                            While tgl = True
                                size = s.Read(data, 0, data.Length)
                                If size > 0 Then
                                    streamWriter.Write(data, 0, size)
                                    tgl = False
                                Else
                                    ' break 
                                    tgl = False
                                End If
    
                            End While
    
                        Finally
                            CType(streamWriter, IDisposable).Dispose()
                        End Try
                    End If
                    entry = s.GetNextEntry
                End While
            Finally
                CType(s, IDisposable).Dispose()
            End Try
    Last edited by .paul.; Oct 18th, 2007 at 04:01 PM.

  4. #4
    Hyperactive Member
    Join Date
    Dec 2005
    Posts
    323

    Re: [2005] SharpZipLibrary Help

    I just installed SharpZipLib today and tried to execute this code on a .gz file and I get an error that says:

    Wrong Local header signature: 0x88B1F

    I can open up the file with WinZip no problem. Any ideas why this would be happening?

    Thanks in advance!

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [2005] SharpZipLibrary Help

    What type of compression is used by the GZ file? Winzip supports more compression formats than does SharpZipLib, so just because you can open it in winzip does not mean SharpZipLib can open it.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] SharpZipLibrary Help

    A GZ file is a GZIP file, not a ZIP file. They are two different compression formats. Did you tell #ZipLib that it was a GZIP file when you tried to extract it or did you just treat it like a ZIP file?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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