1

I just want to access System.IO.Compression.GZipStream class to decompress Web Http response. But I am unable to access GZipStream class due to protection level. I am using Mvvm cross for mobile development.

  • Here is GZipStream class code :

    namespace System.IO.Compression

{

internal class GZipStream : Stream

{
    public GZipStream(Stream stream, CompressionMode mode);
    public GZipStream(Stream stream, CompressionMode mode, bool leaveOpen);

} }

  • I need to access first constructor to create instance of GZipStream.
  • So is there any other way to create GZipStream type instance ?
Uddhao Pachrne
  • 531
  • 1
  • 8
  • 22

2 Answers2

1

In Xamarin Forms for PCL I resolve this problem just replaced TargetFrameworkProfile in your_project_name .csproj

FROM:

Profile259

TO:

Profile111

Also possible to try install NuGet package Microsoft.Bcl.Compression, this option although resolve problem with access to GZipStream, but in time compilation I had System.TypeLoadException.

Polyariz
  • 534
  • 1
  • 7
  • 17
  • Can I know what Profile111 means?How is it different from Profile259? Any impact? – Aashish Mar 09 '20 at 08:28
  • Profile111 compatible with the .NET Standard 1.1 and PCL: .NET Framework 4.5, Windows 8, Windows Phone 8.1 Profile259 - .NET Standard 1.0 and PCL: .NET Framework 4.5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8 There is more: https://learn.microsoft.com/ru-ru/dotnet/standard/net-standard – Polyariz Mar 28 '20 at 11:30
0

You can easily compress byte[] buffer array like this

        using (var ms = new MemoryStream())
        {
            using (var gzip = new GZipStream(ms, CompressionMode.Compress))
            {
                gzip.Write(buffer, 0, buffer.Length);
                gzip.Close();
            }

            compressed = ms.ToArray();
        }
Max Kilovatiy
  • 798
  • 1
  • 11
  • 32