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

Looking for workable zip example.

4 Answers 103 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Patrick asked on 01 May 2012, 08:54 PM
Hi,

I red all documentation and all forum's threads and didn't find a complete workable example that compress/decompress a stream . Every founded examples did not work well. Is it possible to have a complete example closer to a cut and paste?

Regards,

I put my code here. It compresses but the decompression is not functionnal:
Public Class Class1
  
    Dim msCompress As Stream
  
    Public Function Compression(arg As String) As String
        Dim encoding As New System.Text.UTF8Encoding()
        Dim B() As Byte = encoding.GetBytes(arg)
        msCompress = New MemoryStream()
  
        Dim method As ZipCompression = DirectCast([Enum].Parse(GetType(ZipCompression), ZipCompression.Deflate64, False), ZipCompression)
        Dim zipOut As New ZipOutputStream(msCompress, method)
        Dim sWriter As New StreamWriter(zipOut)
  
        sWriter.Write(B)
        sWriter.Flush()
  
        Return ("Compress: " & zipOut.CompressedSize.ToString & ", Uncompress:" & zipOut.UncompressedSize.ToString)
  
    End Function
  
    Public Function Decompression(arg As String) As String
        Dim encoding As New System.Text.UTF8Encoding()
        msCompress.Position = 0
        Dim inputStream As New ZipInputStream(msCompress, False)
        Dim s As String
        Dim Reader As New StreamReader(inputStream.BaseStream, encoding)
        s = Reader.ReadToEnd()
  
        Return s
    End Function
End Class

4 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 04 May 2012, 03:17 PM
Hello Patrick,

I attached a sample solution demonstrating how compress and decompress a string. I hope it will get you started. Let me know if it helps or if I can further assist you.

All the best,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Patrick
Top achievements
Rank 2
answered on 04 May 2012, 04:12 PM
Thanks a lot!
0
Dogan
Top achievements
Rank 1
answered on 13 Jan 2016, 10:07 AM

hi,

 

how to Compress/Decompress object list

0
Nikolay Demirev
Telerik team
answered on 15 Jan 2016, 07:56 AM
Hello Dogan,

You could serialize the objects of the list and compress them. After that to decompress them and deserialize them. Here you could read about serialization. After the serialization the compressing is just the same as in the sample project Tina sent to you.

I hope this helps.

Regards,
Nikolay Demirev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ZipLibrary
Asked by
Patrick
Top achievements
Rank 2
Answers by
Tina Stancheva
Telerik team
Patrick
Top achievements
Rank 2
Dogan
Top achievements
Rank 1
Nikolay Demirev
Telerik team
Share this question
or