In-memory stream compression and decompression

Sometimes, you need to perform some in-memory compression of a large amount of text. You might want to write this to a file or a database. Perhaps you need to e-mail the text as an attachment that another system will pick up and then decompress. Whatever the reason, in-memory compression and decompression is a very useful feature to have around. The best way to do this is to use extension methods. If you haven't figured this out by now, I quite like using extension methods.

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.