1

I have some base-64 encoded zlib data that I'm trying to uncompress into its original string. The following code works fine to do this on .NET Framework 4.8.

string base64 = "eJzzSM3JyVcozy/KSVEEAB0JBF4=";
byte[] bytes = Convert.FromBase64String(base64);
string output;
using (MemoryStream stream = new MemoryStream(bytes))
{
    using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress))
    {
        using (StreamReader reader = new StreamReader(gZipStream))
            output = reader.ReadToEnd();
    }
}
Console.WriteLine(output);

The expected output here is "Hello world!" as a test string. The code, however, fails on .NET Core 2.1 with the following exception:

System.IO.InvalidDataException: The archive entry was compressed using an unsupported compression method. at System.IO.Compression.Inflater.Inflate(FlushCode flushCode) at System.IO.Compression.Inflater.ReadInflateOutput(Byte* bufPtr, Int32 length, FlushCode flushCode, Int32& bytesRead) at System.IO.Compression.Inflater.InflateVerified(Byte* bufPtr, Int32 length) at System.IO.Compression.DeflateStream.ReadCore(Span`1 buffer) at System.IO.Compression.DeflateStream.Read(Byte[] array, Int32 offset, Int32 count) at System.IO.Compression.GZipStream.Read(Byte[] array, Int32 offset, Int32 count) at System.IO.StreamReader.ReadBuffer() at System.IO.StreamReader.ReadToEnd()

The documentation doesn't state, that I can find, on why .NET Core would not be compatible with the zlib format used here.

Is the implementation in Core different somehow? Is it missing entirely?

mjwills
  • 23,389
  • 6
  • 40
  • 63
Dan
  • 1,130
  • 2
  • 20
  • 38
  • 1
    The first two bytes of your data are 78 9c. That looks like a zlib header, not a gzip one ([link](https://en.wikipedia.org/wiki/List_of_file_signatures)) – canton7 Jun 16 '20 at 10:50
  • Repro at https://dotnetfiddle.net/mKZG4Z https://stackoverflow.com/questions/61446785/unzipping-a-gz-file-in-c-sharp-system-io-invaliddataexception-the-archive-en may also be worth a read. – mjwills Jun 16 '20 at 10:54
  • Have you tried https://www.nuget.org/packages/DotNetZip/ ? – mjwills Jun 16 '20 at 11:11
  • Not all ZIP files are the same. There is a ZIP specification and different versions of the ZIP and Optional requirements. It looks like the Core 2.1 library does not support your input ZIP. – jdweng Jun 16 '20 at 11:16

0 Answers0