Compress/Uncompress String

3 posts, 1 answers
  1. Levi
    Levi avatar
    7 posts
    Member since:
    Sep 2011

    Posted 31 Aug 2011 Link to this post

    Good day,

          I have a code as follows to compress I just copied it from the documentation:

    private string CompressString(string str)
                MemoryStream memoryStream = new MemoryStream();
                ZipCompression method = ZipCompression.Default;
                ZipOutputStream zipOutputStream = new ZipOutputStream(memoryStream, method);
                StreamWriter writer = new StreamWriter(zipOutputStream);
                return Convert.ToBase64String(memoryStream.ToArray());

      What is missing is to decompress it, I tried the following code but it doesn't give me the correct output

    private string UnCompressString(string str)

                MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(str));
                ZipInputStream input = new ZipInputStream(memoryStream);
                StreamReader reader = new StreamReader(input.BaseStream);
                string strData = reader.ReadToEnd();
                return strData;


      When I tried to call the uncompressstring method, it does not give me the original text.

  2. Answer
    Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 06 Sep 2011 Link to this post

    Hello Levi,

    I attached a sample project to get you started on your task. It illustrates how to decompress the compressed stream. Please examine the solution and let me know if it works for you.

    Tina Stancheva
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. Levi
    Levi avatar
    7 posts
    Member since:
    Sep 2011

    Posted 07 Sep 2011 Link to this post

    Thank you for the solution.
Back to Top