Looking for workable zip example.

5 posts, 1 answers
  1. Patrick
    Patrick avatar
    31 posts
    Member since:
    Aug 2011

    Posted 01 May 2012 Link to this post

    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
  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 04 May 2012 Link to this post

    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 >>

  3. Patrick
    Patrick avatar
    31 posts
    Member since:
    Aug 2011

    Posted 04 May 2012 Link to this post

    Thanks a lot!
  4. Dogan
    Dogan avatar
    3 posts
    Member since:
    Oct 2013

    Posted 13 Jan in reply to Tina Stancheva Link to this post

    hi,

     

    how to Compress/Decompress object list

  5. Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    103 posts

    Posted 15 Jan Link to this post

    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
Back to Top