Quantcast
Channel: sharpcompress Discussions Rss Feed
Viewing all articles
Browse latest Browse all 239

New Post: How to decompress a compressed string?

$
0
0
Hi everyone. I managed to compress a string with the following method:
public string SharpZip(string asd)
        {
            byte[] sIn = UTF8Encoding.UTF8.GetBytes(asd);

            MemoryStream rawDataStream = new MemoryStream();
            SharpCompress.Compressor.Deflate.DeflateStream gzipOut = new SharpCompress.Compressor.Deflate.DeflateStream(rawDataStream, SharpCompress.Compressor.CompressionMode.Compress);

            gzipOut.Write(sIn, 0, sIn.Length);
            gzipOut.Close();

            byte[] compressed = rawDataStream.ToArray();

            // data sent to the php service
            return Convert.ToBase64String(compressed);
        }
But I'm having trouble to decompress the string. I made various attemps with no luck, being the last one this:
public string SharpUnzip(string asd)
        {
            byte[] sOut = UTF8Encoding.UTF8.GetBytes(asd);
            MemoryStream rawDataStream = new MemoryStream();
            SharpCompress.Compressor.Deflate.DeflateStream gzipOut = new SharpCompress.Compressor.Deflate.DeflateStream(rawDataStream, SharpCompress.Compressor.CompressionMode.Decompress);

            gzipOut.Read(sOut, 0, sOut.Length);
            gzipOut.Close();

            using (var streamReader = new StreamReader(rawDataStream))
            {
                Console.WriteLine(streamReader.ReadToEnd()); // Prints a blank line
            }

            return rawDataStream.ToString(); // Prints System.IO.MemoryStream
            //return "";
        }
Could anyone help me a little here? There doesn't seem to be any documentation on the matter...

Thanks!

Viewing all articles
Browse latest Browse all 239

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>