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

Compress/Uncompress String

2 Answers 196 Views
ZipLibrary
This is a migrated thread and some comments may be shown as answers.
Levi
Top achievements
Rank 1
Levi asked on 01 Sep 2011, 03:02 AM
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);
            writer.Write(str);
            writer.Flush();
            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.

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 06 Sep 2011, 11:52 AM
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.

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

0
Levi
Top achievements
Rank 1
answered on 07 Sep 2011, 10:27 AM
Thank you for the solution.
Tags
ZipLibrary
Asked by
Levi
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Levi
Top achievements
Rank 1
Share this question
or