This is a migrated thread and some comments may be shown as answers.

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

2 Answers 264 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Stalin Vladimir
Top achievements
Rank 1
Stalin Vladimir asked on 11 Apr 2014, 05:47 PM
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 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 14 Apr 2014, 10:34 AM
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.

 
0
Stalin Vladimir
Top achievements
Rank 1
answered on 15 Apr 2014, 08:03 PM
Thank you so much Andrey, it works. 

Cheers
Tags
ZipLibrary
Asked by
Stalin Vladimir
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Stalin Vladimir
Top achievements
Rank 1
Share this question
or