0

I'm currently reading from a sqlite DB. I am having trouble with one column thou ..

The data in that column is compressed. In Java we can use Zlib and we can read that data easily.

data = zlib.decompress(row[3])

I see that Xamarin does not translate zlib in it's IDE and has no standard built in alternative .. Ive seen some Zip components available but are concentrated on files rather than just feeding data directly ..

How would you do this in Xamarin C# ?

EDIT : Code So Far

var   myCompressedData = cursor.GetBlob (cursor.GetColumnIndexOrThrow("TextCompressed")); 
byte[] myCompressedByte = myCompressedData ;
MemoryStream stream = new MemoryStream(myCompressedByte );

using (DeflateStream decompressionStream = new DeflateStream(stream   , CompressionMode.Decompress))
{
    decompressionStream.Read(myCompressedByte  , 0,myCompressedByte.Length  );
}
string UnCompressedString  = System.Text.Encoding.UTF8.GetString(myCompressedByte );

Somehow I'm getting a "{System.IO.IOException: Corrupted data ReadInternal at System.IO.Compression.DeflateStreamNative.Ch…} System.IO.IOException"

This Exception hits on

decompressionStream.Read(myCompressedByte  , 0,myCompressedByte.Length  );
Migz
  • 163
  • 1
  • 13

1 Answers1

0

You can achive this by using the DeflateStream class.

It wraps zlib, or in older versions provides a standard built-in alternative.

This class represents the Deflate algorithm, which is an industry-standard algorithm for lossless file compression and decompression. Starting with the net_v45, the DeflateStream class uses the zlib library.

  • Please have a look at my edit .. trying to get the DeflateStream to work – Migz Feb 01 '16 at 18:14
  • @Migz how to turn a string in to a stream is a seperate question, and one that's been asked a lot: http://stackoverflow.com/questions/8047064/convert-string-to-system-io-stream –  Feb 02 '16 at 08:48
  • Thanks for the tip .. But still not out of the woods yet .. Got an error .. (New Edit ) .. so Close .. BTW, This data was tested in Java and works so not sure why the new error is coming up.. – Migz Feb 02 '16 at 09:56