0

I'm receiving a .zip file from a server.
The .zip file is sent 64Base encoded and it contains an XML file.

After I decode the data to binary using Convert.FromBase64String, can I convert the byte array to XML?

I don't want to deal with unzipping.

I tried the following code: (that resulted in Gibberish that doesn't make any sense and doesn't look like XML at all)

XmlDocument doc = new XmlDocument();
string xml = Encoding.UTF8.GetString(buffer);
doc.LoadXml(xml);

Any ideas?

2 Answers 2

2

You say you don't want to unzip, but do you actually mean that you don't want to unzip to disc? Most zip libraries either allow you to unzip a file to a byte array directly or to a stream where you could pass it a MemoryStream.

There's no getting around having to uncompress. Unless you have control over the server side, then you could change the format to an uncompressed file (like a tar file). Then you wouldn't have to uncompress.

Sign up to request clarification or add additional context in comments.

Comments

1

You say:

I'm receiving a .zip file from a server.

And:

I don't want to deal with unzipping.

Well. You have to. If the data is in a zip archive, you need to extract it first. You can't just ignore the fact.

There are plenty of zip libraries - sharpziplib is free and easy enough to use.

1 Comment

@Sash - No problem. Since it deals with Streams, you can use MemoryStream to manage decompression directly in memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.