0

In C# I compress a big string (1.20 Mbytes) using the function below and then post it to a php page on my server through WebClient :

 public static string Compress(string s)
 {
 var bytes = Encoding.Unicode.GetBytes(s);
 using (var msi = new MemoryStream(bytes))
 using (var mso = new MemoryStream())
 {
    using (var gs = new GZipStream(mso, CompressionMode.Compress))
    {
        msi.CopyTo(gs);
    }
    return Convert.ToBase64String(mso.ToArray());
 }
 }

Basically in C#, I would do the following to decompress it :

 public static string Decompress(string s)
 {
 var bytes = Convert.FromBase64String(s);
 using (var msi = new MemoryStream(bytes))
 using (var mso = new MemoryStream())
 {
    using (var gs = new GZipStream(msi, CompressionMode.Decompress))
    {
        gs.CopyTo(mso);
    }
    return Encoding.Unicode.GetString(mso.ToArray());
 }
 }

But how can I do that in PHP (decompress the string)

Rafik Bari
  • 4,867
  • 18
  • 73
  • 123
  • 1
    Why does it matter that C# was used for encryption? All you are asking is "how to decompress gzip in php"... so perhaps you should trying searching for that and look at one of the many examples – musefan Jan 28 '14 at 13:23
  • 2
    Wouldn't it be easier to enable GZip compression on the HTTP server (Apache) side where the PHP is being executed then everything including the string will get the benefit of the reduction? Save you a lot of code at both sides. This [question](http://stackoverflow.com/questions/12367858/how-can-i-get-apache-gzip-compression-to-work) explains how to do it – Jack Hughes Jan 28 '14 at 13:23
  • Any luck on this? Ain't working to decompress result in php with any gzip function. – mr. Pavlikov Jul 02 '14 at 11:10

0 Answers0