compressionStream(using:writingTo:blockSize:flags:threadCount:)
Creates a compression sequential output stream.
Declaration
static func compressionStream(using compressionAlgorithm: ArchiveCompression, writingTo compressedStream: ArchiveByteStream, blockSize: Int = (1<<20), flags: ArchiveFlags = [], threadCount: Int = 0) -> ArchiveByteStream?Parameters
- compressionAlgorithm:
The compression algorithm.
- compressedStream:
An output stream that receives compressed data, the operation only calls write methods.
- blockSize:
The compression block size, in bytes.
- flags:
Flags that control the behavior of the operation.
- threadCount:
The number of worker threads that the operation uses, set to
0for default.
Return Value
A new archive byte stream.
Discussion
The new stream writes compressed data to the supplied archive byte stream.
The stream that the function returns only implements write(from:) and write(from:atOffset:).
During compression the operation splits the data into blocks of blockSize bytes, compressing each block independently. Larger blocks provide better compression, but require more memory (for compression and decompression) and increase latency in random access.
Good values for blockSize are between 256 KB and 16 MB. The 1 MB default value provides a good compromise between compression ratio and memory requirement.