title: Decompress data in Span<byte> with Deflate algorithm
body: <p>I have a code that parses a binary file. It uses <code>Span&lt;byte&gt;</code> to pass chunks of data among functions to avoid unnecessary memory allocations. </p>
  
  <p>Simplified example:</p>
  
  <pre><code>class Reader {
      bool IsCompressed { get; set; }
      public byte[] Data { get; set; }
  
      function ReadOnlySpan&lt;byte&gt; ReadBlock() {
          ...
      }
  
      public function Read() {
          if (IsCompressed) {
              Data = ???
          } else {
               Data = ReadBlock.ToArray();
          }
  }
  </code></pre>
  
  <p>I can decompress data with <code>Syste.IO.Compression.DeflateStream</code>, but this class accepts only <code>Stream</code> as the input, so I have to convert <code>ReadOnlySpan&lt;byte&gt;</code> to a stream and thus allocate memory for <code>byte[]</code>.</p>
  
  <pre><code>using(var stream = new MemoryStream(buffer.ToArray())) {
      using(var deflateStream = new DeflateStream(stream, CompressionMode.Decompress)) {
          Data = ... read from deflateStream
      }
  }
  </code></pre>
  
  <p>Is there any way to pass <code>ReadOnlySpan&lt;byte&gt;</code> to the <code>DeflateStream</code> without allocating unnecessary memory? Or is there any other library, that can decompress data directly from <code>ReadOnlySpan&lt;byte&gt;</code>?</p>
  
  <p>I am using .NET Core 2.1.0-preview1-26103-03, but I can use any other version if necessary.</p>