问题
I have a simple code
byte[] buffer = Encoding.UTF8.GetBytes("abracadabra");
MemoryStream ms = new MemoryStream();
DeflateStream ds = new DeflateStream(ms, CompressionMode.Compress, false);
ms.Write(buffer, 0, buffer.Length);
DeflateStream ds2 = new DeflateStream(ms, CompressionMode.Decompress, false);
byte[] buffer2 = new byte[ms.Length];
ds2.Read(buffer2, 0, (int)ms.Length);
Console.WriteLine(Encoding.UTF8.GetString(buffer2));
And when reading from ds2, i have the following:
Stacktrace:
at (wrapper managed-to-native) System.IO.Compression.DeflateStream.ReadZStream (intptr,intptr,int) <0x00004>
at (wrapper managed-to-native) System.IO.Compression.DeflateStream.ReadZStream (intptr,intptr,int) <0x00004>
at System.IO.Compression.DeflateStream.ReadInternal (byte[],int,int) [0x00031] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.3\mcs\class\System\System.IO.Compression\DeflateStream.cs:192
at System.IO.Compression.DeflateStream.Read (byte[],int,int) [0x00086] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.3\mcs\class\System\System.IO.Compression\DeflateStream.cs:214
at testtesttest.MainClass.Main (string[]) [0x00041] in C:\Users\ilukyanov\Desktop\Cassini\GZipDemo\Main.cs:27
at (wrapper runtime-invoke) .runtime_invoke_void_object (object,intptr,intptr,intptr)
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.
This problem appears in Mono 2.6.1 & 2.6.3...
Is there any known way to successfully read from DeflateStream in Mono? Or maybe there are some third-party open-source assemblies with the same functionality?
回答1:
You can call zlib natively using Interop with DllImport.
Only trick is to use the right size in the structures and to include the shared library in the LD_LIBRARY_PATH, if you are on a Unix platform.
回答2:
Please file a bug against Mono. If you do so, it might get fixed in time for 2.6.4.
来源:https://stackoverflow.com/questions/2471057/mono-deflatestream