Archived Forum Post

Index of archived forum posts

Question:

Gzip XML Text not being recognized by recipient?

Dec 07 '12 at 05:07

I'm using Chilkat to create a base64 GZip string for sending compressed data to a government service but they get an error decoding/un-gzipping it. What could be the problem?


Answer

The response from your counter-party is still ambiguous because he/she hasn't specified exactly what is required. There are two possibilities:

1) The output should be the Base64 encoded compressed data only. (i.e. the XML text compressed using the deflate compression algorithm with no GZip file format).

or

2) The output should be a complete GZip file (Base64 encoded), i.e. the GZip file format that begins with a header and contains the compressed data. (See the GZip File Format Specification: http://www.ietf.org/rfc/rfc1952.txt )

The Chilkat GZip API provides the ability to produce both cases. The DeflateStringENC and InflateStringENC methods work with just the compressed data (no GZip file format). The Compress* methods output the full GZip file format, and the Decompress* methods expect the full GZip file format. The CompressString method will compress a string (such as your XML string) and return a byte array that contains the full GZip format. You can then Base64 encode this result. I suspect this is what your counter-part actually requires.


Answer

OK finally got my email address validated.

I'm trying what you mention in your last paragraph but

 CompressString(inStr As String, outCharset As String) As Variant

Returns a variant and

 DeflateStringENC(inStr As String, charset As String, encoding As String) As String

takes a string for input and imstruggling to convert between the two in the language i'm using (Visual Dataflex)

Thanks again


Answer

OK I've got a bit further but am still stuck.

I've managed to convert the variant datatype to a string and have tried several combinations without success

Given the input string in sXML this should be the result in sZippedB64 H4sIAElw3j4A/72T7W6CMBSGb8Ub0FKQJUtOTsKH8yNxGjHZ7w46JYF2KTUZd7+2iJO5Zf7a L94+PT08tBSSipU1wkYdnlnNcd2OTGSibJgupQDST8BivUsUf8Moon4wDYH0AHb8cKqYlspF V50ksxcg/chhiW5hRyW659eyd9bWXGiEeZQipFJY/CQVx5Xp0ABxGbKTwpjlVsxGWMhTwzG0 Ni7BVjY6lwXHKPaD0TRJgVwQkHPflGmOvkf9MfXGHjXcAthLzSoMJ54HpMtAnM6N05qp9lpp JYV1vFKi/i9Kj3co0XCoRL07nGL5eq2U1aU+DpVujeLoTiMvGBr5k/BPoRUT/P+MqH+7RzOm qpI3eh4V30/82xRs9JGrpciNCmu5wi3XXI0cNSoOwWY5MAhMmzOCuZJNgzSY2HPvBrBnH2af HgywydReXkEG/3uWZgiJFILnmhfJkalSGzUUEsgP2JTWdVwVh76iH9mPdr1Id6c/ARMJJDLb AwAA

    Move "<Claim><OrgName>My Organisation</OrgName><HMRCref>AA12345</HMRCref><Regulator><RegName>CCEW</RegName><RegNo>A1234</RegNo></Regulator><Repayment><GAD><Donor><Fore>James</Fore><Sur>Bacon</Sur><House>55</House><Postcode>AB23 4CD</Postcode></Donor><Date>2012-10-01</Date><Total>5.00</Total></GAD><GAD><Donor><Fore>Mary</Fore><Sur>Jones</Sur><House>12</House><Postcode>AB23 9CD</Postcode></Donor><Date>2012-10-15</Date><Total>10.00</Total></GAD><GAD><Donor><Fore>Bob</Fore><Sur>Smith</Sur><House>1</House><Postcode>BA23 9CD</Postcode></Donor><Date>2012-10-03</Date><Total>2.50</Total></GAD><GAD><Donor><Fore>Jane</Fore><Sur>Smith</Sur><House>1</House><Postcode>BA23 9CD</Postcode></Donor><Date>2012-10-03</Date><Total>12.00</Total></GAD><EarliestGAdate>2012-10-01</EarliestGAdate><OtherInc><Payer>Peter Other</Payer><OIDate>2012-10-31</OIDate><Gross>13.12</Gross><Tax>2.62</Tax></OtherInc></Repayment><GASDS><ConnectedCharities>no</ConnectedCharities><CommBldgs>no</CommBldgs></GASDS></Claim>" to sXML

    Get Create U_cComGZip to hoZip
    Get ComUnlockComponent  of hoZip UNLOCK_CHILKAT_Zip to bOK
    Get ComCompressString   of hoZip sXML "utf-8" to vZipped
    Move vZipped to baZippedChar
    Move (SizeOfArray(baZippedChar)) to iLoopEnd
    Decrement iLoopEnd
    For iLoop from 0 to iLoopEnd
        Move (Append(sZipped,baZippedChar[iLoop])) to sZipped
    Loop
    Get ComDeflateStringENC of hoZip sZipped "utf-8" "base64" to sZippedB64
    Send Destroy of hoZip

This code gives me HZPJgcQwCART4kbkn5irvfuwRwL6wume9+z/c/d3XnvJm6fVC/Os6PZ8Hju1Pe1tVb2tsrDxSr9xazej3Lf6IsPrVfjz6fDQVUe06+C8RwVtXHBQGRET4+NOiZV7jQDrmtG1Frne9y4AcaopgAxDfRj9vIOGaePHnl/cQ8c2bGL9rv66mHoO44viANwoXS9ExCUs5h44m+PLGzidYXbrwDvP/+XBnVYahQsRaIZIp3SiOstBivdQnOBCQCXJrGei32odKWNAQHbCEEkDYNDvOn/WhabLN10NEv8SIqFy/TpWWrDS1wvUgBYCcQhKZ4uVCWzR99JQgkAanYOuh2P7xlCLdmw/5vC+PtvJMIQqONty3G814jCS8loaOWRpsBWTeFKuVDTlNgou+7AXaksvYBwpAd0apHftSiyozdNi9M1UJl2ANENdD9SSlRH2a4WA8TWGQHhpWWCozWNDjdiDpQHnLYSSgC/+yQyABw7jTCiQBIyIAzCywv3GddEgnhl0zxLy6Fvwf8dP6xeJXZNaWq71wDoWjWAVSWpm//s5xKBG4iUODRaXV1r9kgumo2VzF/nNEOToA2tixR4+iCQHf3vaJX02wx5r6OW/5pdmHw==

Any futher help you can give would be much appreciated


Answer

Hi

I'm really struggling with this

Please see comments in the code below

I really hope you can help because we have a immovable deadline to meet

Function CreateCompressedClaim Returns String
    Handle hoZip hoCrypt
    Boolean bOK
    String sZipped sZippedB64 sXML sZipped2 sXML2
    Variant vZipped vZipped2
    Integer iLoop iLoopEnd
    UChar[] baZippedChar
    UChar[] baZippedChar2

    Move "<Claim><OrgName>My Organisation</OrgName><HMRCref>AA12345</HMRCref><Regulator><RegName>CCEW</RegName><RegNo>A1234</RegNo></Regulator><Repayment><GAD><Donor><Fore>James</Fore><Sur>Bacon</Sur><House>55</House><Postcode>AB23 4CD</Postcode></Donor><Date>2012-10-01</Date><Total>5.00</Total></GAD><GAD><Donor><Fore>Mary</Fore><Sur>Jones</Sur><House>12</House><Postcode>AB23 9CD</Postcode></Donor><Date>2012-10-15</Date><Total>10.00</Total></GAD><GAD><Donor><Fore>Bob</Fore><Sur>Smith</Sur><House>1</House><Postcode>BA23 9CD</Postcode></Donor><Date>2012-10-03</Date><Total>2.50</Total></GAD><GAD><Donor><Fore>Jane</Fore><Sur>Smith</Sur><House>1</House><Postcode>BA23 9CD</Postcode></Donor><Date>2012-10-03</Date><Total>12.00</Total></GAD><EarliestGAdate>2012-10-01</EarliestGAdate><OtherInc><Payer>Peter Other</Payer><OIDate>2012-10-31</OIDate><Gross>13.12</Gross><Tax>2.62</Tax></OtherInc></Repayment><GASDS><ConnectedCharities>no</ConnectedCharities><CommBldgs>no</CommBldgs></GASDS></Claim>" to sXML

    Get Create U_cComGZip to hoZip
    Get ComUnlockComponent  of hoZip UNLOCK_CHILKAT_Zip to bOK
    Get ComCompressString   of hoZip sXML "utf-8" to vZipped
    Move vZipped to baZippedChar
    Move (SizeOfArray(baZippedChar)) to iLoopEnd // this has 381 elements so it matches vZipped

    Decrement iLoopEnd
    For iLoop from 0 to iLoopEnd
        Move (Append(sZipped,(Character(baZippedChar[iLoop])))) to sZipped // This is 381 characters long so matches the array
    Loop

    Get ComDeflateStringENC of hoZip sZipped "utf-8" "base64" to sZippedB64   // this returns some Base64

    Get ComInflateStringENC of hoZip sZippedB64 "utf-8" "base64" to sZipped2  // BUT this returns only 369 completely different characters compared to those passed so something has gone wrong with the data somewhere

    Send Destroy of hoZip

    Function_Return sZippedB64
End_Function

Answer

I added two new methods so you can avoid dealing with Variants: CompressStringENC and UncompressStringENC

These have the same args as DeflateStringENC and InflateStringENC. Here's the new build:
http://www.chilkatsoft.com/preRelease/ChilkatGZip.zip

I tested it and the result begins with "H4sI", but differences follow. This would be normal because the output is a base64-encoded representation of the bytes that are a complete GZip formatted file. The GZip header info would be different (filename, modification time, flags, etc.). See http://www.ietf.org/rfc/rfc1952.txt To get an exact match, you would need to write the same exact header. However, I would think that shouldn't be required.


Answer

Thats great. I shall give it a test out tomorrow and hopefully the government will agree with the answer !


Answer

I've tried a few simple tests and for those it has worked so hopefully that's it

Thanks for all your help

Roughly when will your next release cycle be that will include this and the HTTP oAuth update ?

Cheers