1

The following is used to compress data (C#):

public static string Zip(string value)
    {
        //Transform string into byte[]  
        byte[] byteArray = new byte[value.Length];
        int indexBA = 0;
        foreach (char item in value.ToCharArray())
        {
            byteArray[indexBA++] = (byte)item;
        }

        //Prepare for compress
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress);

        //Compress
        sw.Write(byteArray, 0, byteArray.Length);
        //Close, DO NOT FLUSH cause bytes will go missing...
        sw.Close();

        //Transform byte[] zip data to string
        byteArray = ms.ToArray();
        System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
        foreach (byte item in byteArray)
        {
            sB.Append((char)item);
        }
        ms.Close();
        sw.Dispose();
        ms.Dispose();
        return sB.ToString();
    }

The compressed string is sent via RESTful request to an iOS app.

What options do I have decompressing the resulting NSData object ? I've tried using gzipInflate from here Compression API on the iPhone but the while loop exists early.

Any help or alternative that works with C# GZipStream would be much appreciated.

Community
  • 1
  • 1
matrix4use
  • 611
  • 1
  • 6
  • 20
  • C#? what are you using? Mono? – Michael Dautermann Oct 13 '14 at 23:04
  • @MichaelDautermann No, not Mono.. it's an ASP.Net web application running on IIS6 and .NET framework 2.0 (I know) exposing the compressed to REST requests. – matrix4use Oct 13 '14 at 23:15
  • 1
    Update: I ended up using Chilkat's Gzip library and that works like a charm (http://www.example-code.com/objc/gzip_create_gz.asp). Should I make this an answer instead of a comment ? – matrix4use Oct 16 '14 at 22:26

0 Answers0