O'Reilly logo

C# 7 and .NET Core Cookbook by Dirk Strauss

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create a class called ExtensionMethods that will contain two extension methods called CompressStream() and DecompressStream(). Both these extension methods will act on a byte array and return a byte array:
        public static class ExtensionMethods        {          public static byte[] CompressStream(this byte[] originalSource)          {          }          public static byte[] DecompressStream(this byte[] originalSource)          {          }        }
  1. Looking at the CompressStream() extension method, you need to create a new MemoryStream to return to the calling code. Make use of the using statement so that objects are properly disposed of when they move out of scope. Next, add a new GZipStream object that will compress whatever we give it into the outStream object. You will notice that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required