scoop:scoop.compression:0.1.0
src/options.scoop
Selected production source · src/options.scoop
1
package scoop.compression3
/**4
* The explicit compressed wire format. Decoding does not guess the format from input.5
*/6
public enum CompressionFormat {7
/**8
* DEFLATE inside gzip headers, trailer, and checksum.9
*/10
Gzip,11
/**12
* DEFLATE inside a zlib wrapper.13
*/14
Zlib,15
/**16
* Raw DEFLATE without gzip or zlib framing.17
*/18
RawDeflate,19
/**20
* The Brotli compressed stream format.21
*/22
Brotli,23
/**24
* The Zstandard frame format.25
*/26
Zstd }27
/**28
* The next action required by an incremental codec after consuming and producing the reported byte29
* counts.30
*/31
public enum CompressionState {32
/**33
* Supply more input, or declare the end of input when no more bytes will arrive.34
*/35
NeedInput,36
/**37
* Provide writable output space and continue draining the codec.38
*/39
NeedOutput,40
/**41
* The selected stream or message has reached its terminal boundary.42
*/43
Finished }44
/**45
* The DEFLATE backend's match and entropy-coding strategy.46
*/47
public enum DeflateStrategy {48
/**49
* The backend's general-purpose match strategy.50
*/51
Default,52
/**53
* A strategy favoring filtered data.54
*/55
Filtered,56
/**57
* Entropy coding without string matching.58
*/59
HuffmanOnly,60
/**61
* Run-length-oriented matching.62
*/63
Rle,64
/**65
* Fixed Huffman codes.66
*/67
Fixed }68
/**69
* The content model used by the Brotli encoder.70
*/71
public enum BrotliMode {72
/**73
* General binary content.74
*/75
Generic,76
/**77
* Text-oriented modeling.78
*/79
Text,80
/**81
* Font-oriented modeling.82
*/83
Font }84
/**85
* Controls frame/member boundaries within the selected format; Automatic does not detect the86
* format.87
*/88
public enum DecompressionMode {89
/**90
* Consumes concatenated gzip members or zstd frames; other formats retain their own91
* single-stream boundary.92
*/93
Automatic,94
/**95
* Stops at one frame or member boundary for incremental consumers.96
*/97
Single }99
/**100
* DEFLATE compression level, window bits, and strategy for zlib or raw DEFLATE. Invalid101
* combinations fail during codec construction.102
*/103
public class DeflateOptions public constructor(104
/**105
* The DEFLATE compression level passed to the backend.106
*/107
public val level: Int = 6,108
/**109
* The base-two logarithm of the DEFLATE history window size.110
*/111
public val windowBits: Int = 15,112
/**113
* The match and entropy-coding strategy used by DEFLATE.114
*/115
public val strategy: DeflateStrategy = DeflateStrategy.Default116
)118
/**119
* Optional gzip header metadata with copied filename/comment byte arrays. This metadata does not120
* change the uncompressed payload.121
*/122
public class GzipMetadata public constructor(123
filename: List<Byte>? = None, comment: List<Byte>? = None,124
/**125
* The header modification timestamp in unsigned Unix seconds.126
*/127
public val modifiedUnixSeconds: UInt = 0U,128
/**129
* Whether the encoder includes a gzip header CRC.130
*/131
public val headerCrc: Boolean = false132
) {133
/**134
* An optional copied gzip original-filename field.135
*/136
public val filename: Array<Byte>? = when (filename) { case Some(val bytes) -> Some(bytes.toArray()); case None -> None }137
/**138
* An optional copied gzip comment field.139
*/140
public val comment: Array<Byte>? = when (comment) { case Some(val bytes) -> Some(bytes.toArray()); case None -> None }141
}143
/**144
* DEFLATE parameters and gzip header metadata for a gzip member.145
*/146
public class GzipOptions public constructor(147
/**148
* The DEFLATE compression level passed to the backend.149
*/150
public val level: Int = 6,151
/**152
* The base-two logarithm of the DEFLATE history window size.153
*/154
public val windowBits: Int = 15,155
/**156
* The match and entropy-coding strategy used by DEFLATE.157
*/158
public val strategy: DeflateStrategy = DeflateStrategy.Default,159
/**160
* The gzip header metadata emitted before compressed data.161
*/162
public val metadata: GzipMetadata = GzipMetadata()163
)165
/**166
* Brotli quality, window size, and content mode; invalid values fail at codec construction.167
*/168
public class BrotliOptions public constructor(169
/**170
* The encoder's quality level, trading work for compressed size.171
*/172
public val quality: Int = 5,173
/**174
* The base-two logarithm of the Brotli history window size.175
*/176
public val windowBits: Int = 22,177
/**178
* The content model selected for the Brotli encoder.179
*/180
public val mode: BrotliMode = BrotliMode.Generic181
)183
/**184
* Zstandard level, frame checksum selection, and optional dictionary. The default is level 3 with185
* checksum enabled.186
*/187
public class ZstdOptions public constructor(188
/**189
* The zstd compression level passed to the backend.190
*/191
public val level: Int = 3,192
/**193
* Whether the encoder emits a frame content checksum.194
*/195
public val checksum: Boolean = true,196
/**197
* An optional zstd dictionary used when constructing the encoder.198
*/199
public val dictionary: CompressionDictionary? = None200
)202
/**203
* A format and its matching encoder settings; generic compression defaults to zstd.204
*/205
public enum CompressionOptions {206
/**207
* DEFLATE inside gzip headers, trailer, and checksum. The payload supplies this format's208
* encoder settings.209
*/210
Gzip(val value: GzipOptions),211
/**212
* DEFLATE inside a zlib wrapper. The payload supplies this format's encoder settings.213
*/214
Zlib(val value: DeflateOptions),215
/**216
* Raw DEFLATE without gzip or zlib framing. The payload supplies this format's encoder217
* settings.218
*/219
RawDeflate(val value: DeflateOptions),220
/**221
* The Brotli compressed stream format. The payload supplies this format's encoder settings.222
*/223
Brotli(val value: BrotliOptions),224
/**225
* The Zstandard frame format. The payload supplies this format's encoder settings.226
*/227
Zstd(val value: ZstdOptions)229
/**230
* The wire format selected by this options variant.231
*/232
public val format: CompressionFormat get() = when (this) {233
case Gzip(_) -> CompressionFormat.Gzip234
case Zlib(_) -> CompressionFormat.Zlib235
case RawDeflate(_) -> CompressionFormat.RawDeflate236
case Brotli(_) -> CompressionFormat.Brotli237
case Zstd(_) -> CompressionFormat.Zstd238
}239
}241
/**242
* An explicit decoder format with optional output/window limits and dictionary. Dictionary and243
* window-limit support belong to zstd.244
*/245
public class DecompressionOptions public constructor(246
/**247
* The required input format; default Zstd does not imply format detection.248
*/249
public val format: CompressionFormat = CompressionFormat.Zstd,250
/**251
* An optional zstd dictionary; unsupported format combinations are rejected.252
*/253
public val dictionary: CompressionDictionary? = None,254
/**255
* An optional nonnegative limit on uncompressed bytes produced.256
*/257
public val maxOutputBytes: Long? = None,258
/**259
* An optional positive zstd window-size limit in bytes.260
*/261
public val maxWindowBytes: Long? = None,262
/**263
* Whether to consume supported concatenated frames or stop at one boundary.264
*/265
public val mode: DecompressionMode = DecompressionMode.Automatic266
)268
/**269
* Actual input bytes consumed, output bytes produced, and the next required codec action for one270
* call.271
*/272
public struct CompressionStep(val consumed: Long, val produced: Long, val state: CompressionState)273
/**274
* Cumulative actual input and output byte counts, not buffer capacities or requested counts.275
*/276
public struct CompressionTotals(val inputBytes: Long, val outputBytes: Long)278
internal fun compressionFormatCode(format: CompressionFormat): Int = when (format) {279
case Gzip -> 0; case Zlib -> 1; case RawDeflate -> 2; case Brotli -> 3; case Zstd -> 4280
}282
internal fun deflateStrategyCode(strategy: DeflateStrategy): Int = when (strategy) {283
case Default -> 0; case Filtered -> 1; case HuffmanOnly -> 2; case Rle -> 3; case Fixed -> 4284
}