Kitura compression middleware for compressing body data sent back to the client. Supports deflate and gzip compression methods. Uses zlib.
Swift version
The latest version of Kitura-Compression requires Swift 4.0 or newer. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.
Usage
Add dependencies
Add the Kitura-Compression package to the dependencies within your application’s Package.swift file. Substitute "x.x.x" with the latest Kitura-Compressionrelease.
You can configure Compression with optional arguments:
public init (threshold: Int = 1024, chunkSize: Int = 16384, compressionLevel: CompressionLevel = CompressionLevel.defaultCompression, compressionStrategy: CompressionStrategy = CompressionStrategy.defaultStrategy, memoryLevel: Int32 = 8)
Where:
threshold is the byte threshold for the response body size before compression is considered for the response, defaults to 1024.
chunkSize is the size of internal output slab buffer in bytes, defaults to 16384.
compressionLevel is the level of zlib compression to apply. The supported values are: .noCompression, .bestSpeed, .bestCompression, .defaultCompression
compressionStrategy is used to tune the compression algorithm. The possible values are: .defaultStrategy, .filtered, .huffmanOnly, .rle, .fixed
memoryLevel specifies how much memory should be allocated
for the internal compression state. The default value is 8.
For more information on compression parameters, see the zlib manual.
Kitura-Compression
Kitura compression middleware for compressing body data sent back to the client. Supports
deflate
andgzip
compression methods. Uses zlib.Swift version
The latest version of Kitura-Compression requires Swift 4.0 or newer. You can download this version of the Swift binaries by following this link. Compatibility with other Swift versions is not guaranteed.
Usage
Add dependencies
Add the
Kitura-Compression
package to the dependencies within your application’sPackage.swift
file. Substitute"x.x.x"
with the latestKitura-Compression
release.Add
KituraCompression
to your target’s dependencies:Import package
Using Compression
In order to use compression middleware, create an instance of
Compression
, and connect it to the desired path:You can configure
Compression
with optional arguments:Where:
threshold is the byte threshold for the response body size before compression is considered for the response, defaults to 1024.
chunkSize is the size of internal output slab buffer in bytes, defaults to 16384.
compressionLevel is the level of zlib compression to apply. The supported values are:
.noCompression, .bestSpeed, .bestCompression, .defaultCompression
compressionStrategy is used to tune the compression algorithm. The possible values are:
.defaultStrategy, .filtered, .huffmanOnly, .rle, .fixed
memoryLevel specifies how much memory should be allocated for the internal compression state. The default value is 8.
For more information on compression parameters, see the zlib manual.
API Documentation
For more information visit our API reference.
Community
We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!
License
This library is licensed under Apache 2.0. Full license text is available in LICENSE.