How to compress and decompress files *.dll, *.exe

3 posts, 0 answers
  1. Stalin Vladimir
    Stalin Vladimir avatar
    2 posts
    Member since:
    Apr 2014

    Posted 11 Apr 2014 Link to this post

    I'm trying to compress and decompress file with ZipLibrary. But it doesn't works. Can anybody help me?

     Private Function Compress(data As Byte()) As Byte()
            Dim result As Byte() = Nothing
            Try
                Using memoryStream As New MemoryStream()
                    Dim method As ZipCompression = ZipCompression.Deflate64
                    Using zipOutputStream As New ZipOutputStream(memoryStream, method)
                        Using writer As New StreamWriter(zipOutputStream)
                            writer.Write(data)
                            writer.Flush()
                            result = memoryStream.ToArray()
                        End Using
                    End Using
                End Using
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
            Return result
        End Function

      Private Function UnCompress(data As Byte()) As Byte()
            Dim result As Byte() = Nothing
            Try
                Using memoryStream As New MemoryStream(data)
                    Using zipInputStream As New ZipInputStream(memoryStream)
                        Using reader As New StreamReader(zipInputStream)
                            result = memoryStream.ToArray
                        End Using
                    End Using
                End Using
            Catch ex As Exception

            End Try
            Return result
        End Function

  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 14 Apr 2014 Link to this post

    Hi Stalin Vladimir,

    You can use the following sample code:
    Private Function Compress(data As Byte()) As Byte()
        Dim result As Byte()
        Using outputStream As New MemoryStream()
            Using inputStream As New MemoryStream(data)
                Using zipOutputStream As New ZipOutputStream(outputStream, ZipCompression.Deflate64)
                    inputStream.CopyTo(zipOutputStream)
                End Using
            End Using
            result = outputStream.ToArray
        End Using
        Return result
    End Function
     
    Private Function UnCompress(data As Byte()) As Byte()
        Dim result As Byte()
        Using outputStream As New MemoryStream()
            Using inputStream As New MemoryStream(data)
                Using zipInputStream As New ZipInputStream(inputStream)
                    zipInputStream.CopyTo(outputStream)
                End Using
            End Using
            result = outputStream.ToArray
        End Using
        Return result
    End Function

    Regards,
    Andrey Murzov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Stalin Vladimir
    Stalin Vladimir avatar
    2 posts
    Member since:
    Apr 2014

    Posted 15 Apr 2014 in reply to Andrey Link to this post

    Thank you so much Andrey, it works. 

    Cheers
Back to Top