I am using ZLIB.Net and I just don't understand what should I do to compress a stream which is not FileStream
, but MemoryStream
. By doing:
byte[] buffer = ASCIIEncoding.ASCII.GetBytes("Hello World");
MemoryStream outStream = new MemoryStream();
zlib.ZOutputStream outZStream = new zlib.ZOutputStream(
outStream,
zlib.zlibConst.Z_BEST_COMPRESSION);
outZStream.Write(buffer, 0, buffer.Length);
outZStream.finish();
buffer = outStream.GetBuffer();
Debug.WriteLine(DateTime.Now.ToString() + ":" + buffer.Length);
MemoryStream inStream = new MemoryStream(buffer);
MemoryStream mo = new MemoryStream();
zlib.ZInputStream inZStream = new zlib.ZInputStream(
inStream,
zlib.zlibConst.Z_BEST_COMPRESSION);
int n = 0;
while ((n = inZStream.Read(buffer, 0, buffer.Length)) > 0)
{
mo.Write(buffer, 0, n);
}
string STR = ASCIIEncoding.ASCII.GetString(mo.GetBuffer());
I can't get the string "Hello World"
back.