October 2009
M T W T F S S
    Nov »
 1234
567891011
12131415161718
19202122232425
262728293031  

Archives

Categories

  • [+]ASP.NET (7) 
  • [—]C# (87) 
  • [+]C++ (13) 
  • [+]Delphi (20) 
  • [+]JavaScript (24) 
  • [+]Regular Expressions (7) 
  • [+]SQL (13) 
  • [+]VB (100) 
  • [+]VB.NET (4) 

Online

Users: 8 Guests
  • Loading...


    Loading...

    Login






    Register | Lost password?

    Register





    A password will be mailed to you.
    Log in | Lost password?

    Retrieve password





    A confirmation mail will be sent to your e-mail address.
    Log in | Register
  • XML (or any string type) compression

    Author: Miroslav Stampar

    URL: http://mstampar.awardspace.com/

    // XML (or any string type) compression
    
            public static byte[] CompressXML(string xml)
            {
                byte[] temp = Encoding.UTF8.GetBytes(xml);
                MemoryStream ms = new MemoryStream();
                DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress);
                ds.Write(temp, 0, temp.Length);
                ds.Flush();
                ds.Close();
                return ms.ToArray();
            }
    
            public static string DecompressXML(byte[] data)
            {
                const int BUFFER_SIZE = 10;
                byte[] tempArray = new byte[BUFFER_SIZE];
                ArrayList tempList = new ArrayList();
                int count = 0, length = 0;
    
                MemoryStream ms = new MemoryStream(data);
                DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress);
    
                while ((count = ds.Read(tempArray, 0, BUFFER_SIZE)) > 0)
                {
                    if (count == BUFFER_SIZE)
                    {
                        tempList.Add(tempArray);
                        tempArray = new byte[BUFFER_SIZE];
                    }
                    else
                    {
                        byte[] temp = new byte[count];
                        Array.Copy(tempArray, 0, temp, 0, count);
                        tempList.Add(temp);
                    }
                    length += count;
                }
    
                byte[] retVal = new byte[length];
    
                count = 0;
                foreach (byte[] temp in tempList)
                {
                    Array.Copy(temp, 0, retVal, count, temp.Length);
                    count += temp.Length;
                }
    
                return Encoding.UTF8.GetString(retVal);
            }
    

    Share: These icons link to social bookmarking sites where readers can share and discover new web pages.
    • Digg
    • del.icio.us
    • Bloglines
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Technorati
    • TwitThis
    • Webnews

    Leave a Reply

     

     

     

    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

    Spam Protection by WP-SpamFree Plugin