Skip to content

Commit

Permalink
Use ZlibConfiguration enums (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler authored Nov 18, 2024
1 parent 1fc402c commit 947b17b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
.package(url: "https://github.com/adam-fowler/compress-nio.git", from: "1.3.0"),
.package(url: "https://github.com/adam-fowler/compress-nio.git", from: "1.4.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.1"),
],
targets: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,19 @@ public struct ResponseCompressionMiddleware<Context: RequestContext>: RouterMidd
/// - Parameters:
/// - windowSize: Compression window size
/// - minimumResponseSizeToCompress: Minimum size of response before applying compression
/// - zlibCompressionLevel: zlib compression level to use. Value between 0 and 9 where 1 is fastest, 9 is best compression and
/// 0 is no compression.
/// - zlibMemoryLevel: Amount of memory to use when compressing. Less memory will mean the compression will take longer
/// and compression level will be reduced. Value between 1 - 9 where 1 is least amount of memory.
/// - zlibCompressionLevel: zlib compression level.
/// - zlibMemoryLevel: Amount of memory to allocated for compression state.
public init(
windowSize: Int = 32768,
minimumResponseSizeToCompress: Int = 1024,
zlibCompressionLevel: Int? = nil,
zlibMemoryLevel: Int? = nil
zlibCompressionLevel: ZlibConfiguration.CompressionLevel = .defaultCompressionLevel,
zlibMemoryLevel: ZlibConfiguration.MemoryLevel = .defaultMemoryLevel
) {
self.windowSize = windowSize
self.minimumResponseSizeToCompress = minimumResponseSizeToCompress
self.zlibConfiguration = .init(
compressionLevel: numericCast(zlibCompressionLevel ?? -1), // -1 indicates use the default compression level set by the library
memoryLevel: numericCast(zlibMemoryLevel ?? 8) // 8 is the default value for the library
compressionLevel: zlibCompressionLevel,
memoryLevel: zlibMemoryLevel
)
}

Expand Down

0 comments on commit 947b17b

Please sign in to comment.