Help with Compressed Data from Database

Sep 15, 2011 at 3:31 PM

Hi All,

I have an XML string that is compressed and stored in a database, can anyone point me in the right direction on how to decompress and get to the actual XML.
I have tried writing a few different solutions using the examples from the site but to no avail. It seems to be "zip" compressed due to the magic number header.
Here is the header from the string in the database below.

0x504B0304140001000800BA552D3F6991256F4F0700007B5D00005400240055534552532F5244555155457E312F4150
50444154412F4C4F43414C2F54454D502F33332F7E54454D504E4734353145354132322D323745422D344342432D413
731312D3631433834343541373335312E5341560A

Any information would be greatly apperciated.

Ron Duquette

 

Coordinator
Sep 15, 2011 at 7:08 PM

you'll need to hex-decode that string.

Strip the first two characters.  Then, taking 2 characters at a time, convert that string to an array of bytes. Then, you can create a MemoryStream around that array, and use the ZipFile.Read() method to read in the zipfile from that MemoryStream.

// assume s is a string containing "0x504b03040390393039...."
var a = new byte[s.Length/2 -1];
for (int i=0; i+2 < s.Length; i+=2) 
{
    a[i/2] = Int32.Parse(s.Substring(i+2,2), NumberStyles.AllowHexSpecifier);
}

var ms = new MemoryStream(a);
using (var zip = ZipFile.Read(ms)) 
{
    ....// read zipfile here
}

 

Sep 15, 2011 at 8:11 PM

Worked like a charm. Thanks so much for your help.

Coordinator
Sep 16, 2011 at 12:18 AM

No charge.