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 ...

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.