简体   繁体   中英

Xamarin C# for Android : Zlib alternative

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  );

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM