Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ZlibConfiguration enums #25

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading