title: How to decompress a Flux<DataBuffer> (and how to write one)?
body: <p>I have a requirement to read and write compressed (GZIP) streams without intermediate storage. Currently, I'm using Spring <code>RestTemplate</code> to do the writing, and Apache HTTP client to do the reading (see my answer <a href="https://stackoverflow.com/a/48041200/839733">here</a> for an explanation of why <code>RestTemplate</code> can't be used for reading large streams). The implementation is fairly straightforward, where I slap a <code>GZIPInputStream</code> on the response <code>InputStream</code> and move on.</p>
  
  <p>Now, I'd like to switch to using Spring 5 <a href="https://docs.spring.io/spring/docs/5.0.2.RELEASE/spring-framework-reference/web-reactive.html#webflux-client" rel="noreferrer">WebClient</a> (just because I'm not a fan of status quo). However, <code>WebClient</code> is reactive in nature and deals with <code>Flux&lt;Stuff&gt;</code>; I believe it's possible to get a <code>Flux&lt;DataBuffer&gt;</code>, where <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/io/buffer/DataBuffer.html" rel="noreferrer">DataBuffer</a> is an abstraction over <code>ByteBuffer</code>. Question is, how do I decompress it on the fly without having to store the full stream in memory (<code>OutOfMemoryError</code>, I'm looking at you), or writing to local disk? It's worth mentioning that <code>WebClient</code> uses Netty under the hood.</p>
  
  <ul>
  <li>Also see Reactor Netty <a href="https://github.com/reactor/reactor-netty/issues/251" rel="noreferrer">issue-251</a>.</li>
  <li>Also related to Spring integration <a href="https://github.com/spring-projects/spring-integration/issues/2300" rel="noreferrer">issue-2300</a>.</li>
  </ul>
  
  <p>I'll admit to not knowing much about (de)compression, however, I did my research, but none of the material available online seemed particularly helpful.</p>
  
  <p><a href="https://stackoverflow.com/q/8766351/839733">compression on java nio direct buffers</a></p>
  
  <p><a href="https://stackoverflow.com/q/9394098/839733">Writing GZIP file with nio</a></p>
  
  <p><a href="https://stackoverflow.com/q/3335969/839733">Reading a GZIP file from a FileChannel (Java NIO)</a></p>
  
  <p><a href="https://stackoverflow.com/q/7175893/839733">(de)compressing files using NIO</a></p>
  
  <p><a href="https://stackoverflow.com/q/13387215/839733">Iterable gzip deflate/inflate in Java</a></p>