tags:

views:

872

answers:

5

I have a Base64-encoded object with the following header:

application/x-xfdl;content-encoding="asc-gzip"

What is the best way to proceed in decoding the object? Do I need to strip the first line? Also, if I turn it into a byte array (byte[]), how do I un-gzip it?

Thanks!

+3  A: 

To unencode the Base64 content you can use the Covert Class static members.

See msdn link: http://msdn.microsoft.com/en-us/library/system.convert_members.aspx

You can also use the GZipStream Class in .net: http://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream.aspx

Or SharpZipLib See link: http://www.icsharpcode.net/OpenSource/SharpZipLib/

This will allow you to extract the original data from the compresses data.

scptre
A: 

For java, have you tried java's built in java.util.zip package? Alternately, Apache Commons has the Commons Compress library to work with zip, tar and other compressed file types. As to decoding Base 64, there are several open source libraries, or you can use Sun's sun.misc.BASE64Decoder class.

+1  A: 

In Java, you can use the Apache Commons Base64 class

String decodedString = new String(Base64.decodeBase64(encodedBytes));
Spike Williams
+1  A: 

It sounds like you're dealing with data that is both gzipped and Base 64 encoded. Once you strip off any mime headers, you should convert the Base64 data to a byte array using something like Apache commons codec. You can then wrap the byte[] in a ByteArrayInputStream object and pass that to a GZipInputStream which will let you read the uncompressed data.

Jherico
A: 

I think I misspoke initially. By saying the header was

application/x-xfdl;content-encoding="asc-gzip"

I meant this was the first line of the file. So in order to use the java or c# libraries to decode the file, does this line need to be stripped?

If so, what is the simplest way to strip the first line?

Jason