Skip to content

Commit

Permalink
Move compression package
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw committed Dec 27, 2024
1 parent 287017d commit 4e81207
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sttp.client4.internal.compression
package sttp.client4.compression

import sttp.client4._
import sttp.model.Encodings
Expand All @@ -10,12 +10,12 @@ import java.util.zip.DeflaterInputStream
import java.util.zip.Deflater
import java.io.ByteArrayOutputStream

private[client4] trait Compressor[R] {
trait Compressor[R] {
def encoding: String
def apply(body: GenericRequestBody[R], encoding: String): GenericRequestBody[R]
}

private[client4] class GZipDefaultCompressor[R] extends Compressor[R] {
class GZipDefaultCompressor[R] extends Compressor[R] {
val encoding: String = Encodings.Gzip

def apply(body: GenericRequestBody[R], encoding: String): GenericRequestBody[R] =
Expand Down Expand Up @@ -44,7 +44,7 @@ private[client4] class GZipDefaultCompressor[R] extends Compressor[R] {
}
}

private[client4] class DeflateDefaultCompressor[R] extends Compressor[R] {
class DeflateDefaultCompressor[R] extends Compressor[R] {
val encoding: String = Encodings.Deflate

def apply(body: GenericRequestBody[R], encoding: String): GenericRequestBody[R] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package sttp.client4.internal.compression
package sttp.client4.compression

import java.io.{ByteArrayInputStream, IOException, InputStream}
import java.util.zip.{CRC32, Deflater}

// based on:
// https://github.com/http4k/http4k/blob/master/core/core/src/main/kotlin/org/http4k/filter/Gzip.kt#L124
// https://stackoverflow.com/questions/11036280/compress-an-inputstream-with-gzip
private[client4] class GZIPCompressingInputStream(
class GZIPCompressingInputStream(
source: InputStream,
compressionLevel: Int = java.util.zip.Deflater.DEFAULT_COMPRESSION
) extends InputStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sttp.client4.httpurlconnection
import sttp.capabilities.Effect
import sttp.client4.httpurlconnection.HttpURLConnectionBackend.EncodingHandler
import sttp.client4.internal._
import sttp.client4.internal.compression.{Compressor, DeflateDefaultCompressor, GZipDefaultCompressor}
import sttp.client4.compression.{Compressor, DeflateDefaultCompressor, GZipDefaultCompressor}
import sttp.client4.testing.SyncBackendStub
import sttp.client4.ws.{GotAWebSocketException, NotAWebSocketException}
import sttp.client4.{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

import java.io.ByteArrayInputStream
import java.util.zip.GZIPInputStream
import sttp.client4.compression.GZIPCompressingInputStream

class GZIPCompressingInputStreamTest extends AnyFlatSpec with Matchers with ScalaCheckPropertyChecks {
implicit override val generatorDrivenConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.net.http.HttpResponse.BodyHandlers
import java.util.concurrent.Flow.Publisher
import java.{util => ju}
import scala.collection.JavaConverters._
import sttp.client4.internal.compression.Compressor
import sttp.client4.compression.Compressor
import sttp.client4.httpclient.fs2.compression.{DeflateFs2Compressor, GZipFs2Compressor}

class HttpClientFs2Backend[F[_]: Async] private (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sttp.client4.httpclient.fs2.compression

import sttp.client4._
import sttp.client4.internal.compression._
import sttp.client4.GenericRequestBody
import fs2._
import fs2.compression.Compression
Expand All @@ -10,6 +9,7 @@ import fs2.io.file.Files
import cats.effect.Sync
import sttp.capabilities.fs2.Fs2Streams
import fs2.compression.DeflateParams
import sttp.client4.compression.{Compressor, DeflateDefaultCompressor, GZipDefaultCompressor}

trait Fs2Compressor[F[_], R <: Fs2Streams[F]] extends Compressor[R] {
protected val fSync: Sync[F]
Expand Down

0 comments on commit 4e81207

Please sign in to comment.