All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sttp.client4.httpclient.fs2.Fs2Compression.scala Maven / Gradle / Ivy

There is a newer version: 4.0.0-M24
Show newest version
package sttp.client4.httpclient.fs2

import fs2.{Pipe, Pull}
import fs2.compression.{Compression, InflateParams, ZLibParams}

object Fs2Compression {

  def inflateCheckHeader[F[_]: Compression]: Pipe[F, Byte, Byte] = stream =>
    stream.pull.uncons1
      .flatMap {
        case None                 => Pull.done
        case Some((byte, stream)) => Pull.output1((byte, stream))
      }
      .stream
      .flatMap { case (byte, stream) =>
        val header = if ((byte & 0x0f) == 0x08) ZLibParams.Header.ZLIB else ZLibParams.Header.GZIP
        val params = InflateParams(header = header)
        stream.cons1(byte).through(fs2.compression.Compression[F].inflate(params))
      }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy