By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,687 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,687 IT Pros & Developers. It's quick & easy.

Base64 encoded compressed webresponse

P: n/a
BW
Sorted my problem.

Issue - retrieve Base64 encoded Zlib compressed XML stream.

The compressed XML stream was compressed using Zlib on a Java
platform.

Resolution. (VB.NET)

1) Retrieve XML stream using webresponse class
2) Convert the base64 encoded stream into a byte array
3) Feed the byte array into the amazing SharpZipLib C# library
developed by Mike Krueger. (available at
http://www.icsharpcode.net/OpenSource/SharpZipLib/)
4) Retirieved the resulting byte array into a string.

Code in VB.NET is below (steps 2-4)

'string containing data
dim b64stringas string = "mybase64encoded_compressed_string"
'decode base64 encoded string into a bte array
Dim data() As Byte = Convert.FromBase64String(b64string)
'declare my variables for using the SharpZipLib componant
dim strresult as String
dim totalLength as long= 0
dim writedata(4096) as Byte
dim size as Integer
'make memory stream to feed into InflaterInputStream
dim s2 as Stream = new
ICSharpCode.SharpZipLib.Zip.Compression.Streams.In flaterInputStream(new
MemoryStream(data1))
do while true
size = s2.Read(writeData, 0, writeData.Length)
if (size > 0)
strResult+=System.Text.Encoding.UTF8.GetString(wri teData,
0,size)
else
exit Do
End If
Loop
'write the results out to a file
Dim objReader As StreamWriter
objReader = New StreamWriter("c:\hereyougo.txt")
objReader.Write(strresult)
objReader.Close()
Nov 22 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.