Hello,
I represent a company that's been using Xceed components for a number of years. In one of our legacy products we compress and base64 encode a stream of data and store it in a file. I've been tasked to extract, decode, and decompress this data, but we would like to use your .NET components to do so. I have found a thread simply stating that this can be done (http://xceed.com/CS/forums/post/12154.aspx), but it doesn't provide an implementation.
Our legacy product uses Interop to call into the XceedZip library, this is the code used to store the data:
<code>
XceedStreamingCompressionLib.XceedStreamingCompression objStream = new XceedStreamingCompressionLib.XceedStreamingCompressionClass();
objStream.License("xxx");
XceedStreamingCompressionLib.XceedBWTCompressionMethod objMethod = new XceedStreamingCompressionLib.XceedBWTCompressionMethodClass();
objMethod.CompressionLevel = XceedStreamingCompressionLib.EXCCompressionLevel.cclMedium;
objStream.CompressionFormat = objMethod;
XceedBinaryEncodingLib.XceedBinaryEncoding objEncoder = new XceedBinaryEncodingLib.XceedBinaryEncodingClass();
objEncoder.License("xxx");
objEncoder.EncodingFormat = new XceedBinaryEncodingLib.XceedBase64EncodingFormatClass();
object OData = sData;
object CData = objStream.Compress(ref OData, true);
object EData = objEncoder.Encode(ref CData, true);
objEncoder = null;
objMethod = null;
objStream = null;
return Encoding.Unicode.GetString((byte[])EData);
</code>
If I understand correctly, this compresses an input string using BWT medium compression and then encodes the result as a base 64 unicode string so we can store it in our propietary XML file format.
Now, according to the forum thread I posted earlier, I should be able to use .NET's class library to decode the base 64 string, use BWT "normal" decompression, and end up with the original string? This is a sample of the code that attempts to do this. I'm using build 3.7.8465.14130 of the Xceed .NET components.
<code>
// parse through proprietary file, return the encoded and compressed string "data"
// This will raise a FormatException "Invalid character in a Base-64 string"
var bytes = Convert.FromBase64String(data);
// So I tried manually creating a UTF8 encoding and passing in false to "throw exception on invalid characters" (second param of constructor)
/*
var encoding = new UTF8Encoding(false, false);
var utf8String = encoding.GetString(Encoding.Unicode.GetBytes(data));
var decoded64Bytes = Convert.FromBase64String(utf8String); */
// I was able to get a byte array that happily went into an XceedCompressedStream, but when I tried to read from the stream
// I received a NotSupportedException "The XceedCompressedStream does not support having data written in its reserved bits."
var xceedCompressedStream = new XceedCompressedStream(new MemoryStream(bytes), CompressionMethod.BWT, CompressionLevel.Normal);
var outputStream = new MemoryStream();
// 32K at at time.
var buffer = new byte[32768];
int bytesRead;
// Loop until we have nothing more to read from the source stream.
while ((bytesRead = xceedCompressedStream.Read(buffer, 0, buffer.Length)) > 0)
{
outputStream.Write(buffer, 0, bytesRead);
}
</code>
As a last resort we will use the ActiveX COM component to do the decoding and decompression (I've already tested that implementation and it works as advertised), but we would really appreciate some assistance getting this working with the .NET components so we don't have to have a COM dependency.
Thanks,