scoop:scoop.compression:0.1.0
src/engines.scoop
Selected production source · src/engines.scoop
1
package scoop.compression3
import scoop.platform.memory.NativeByteBuffer5
/**6
* A stateful incremental encoder using caller-owned input and output buffers. Drain flush/finish7
* until their operation completes; close releases native state without completing a stream.8
*/9
public class CompressionEncoder public constructor(10
options: CompressionOptions = CompressionOptions.Zstd(ZstdOptions())11
) : Closeable {12
private val codec: CompressionCodec = createCompressionEncoder(options)13
/**14
* The explicitly selected compressed wire format.15
*/16
public val format: CompressionFormat get() = codec.format17
/**18
* The actual cumulative byte counts accepted and produced by this codec.19
*/20
public val totals: CompressionTotals get() = codec.totals21
/**22
* The recorded terminal failure, or None before failure.23
*/24
public val failure: Throwable? get() = codec.failure26
/**27
* Consumes at most count readable input bytes and appends encoded bytes to output, advancing28
* both cursors by the returned counts.29
*/30
public fun process(input: NativeByteBuffer, output: NativeByteBuffer, count: Long = input.readableBytes): CompressionStep =31
codec.step(Some(input), count, output, output.writableBytes, 0)32
/**33
* Produces a format synchronization point without ending input; drain output before resuming34
* input.35
*/36
public fun flush(output: NativeByteBuffer): CompressionStep = codec.step(None, 0L, output, output.writableBytes, 1)37
/**38
* Ends input and drains final format bytes. Continue with output space until Finished.39
*/40
public fun finish(output: NativeByteBuffer): CompressionStep = codec.step(None, 0L, output, output.writableBytes, 2)41
/**42
* Releases native codec state. Closing does not finish incomplete stream or message data.43
*/44
public override fun close() { codec.close() }45
}47
/**48
* A stateful incremental decoder for one explicitly selected format. It validates framing and49
* configured limits while advancing caller-owned buffers.50
*/51
public class CompressionDecoder public constructor(options: DecompressionOptions = DecompressionOptions()) : Closeable {52
private val codec: CompressionCodec = createCompressionDecoder(options)53
/**54
* The explicitly selected compressed wire format.55
*/56
public val format: CompressionFormat get() = codec.format57
/**58
* The actual cumulative byte counts accepted and produced by this codec.59
*/60
public val totals: CompressionTotals get() = codec.totals61
/**62
* The recorded terminal failure, or None before failure.63
*/64
public val failure: Throwable? get() = codec.failure66
/**67
* Consumes at most count bytes and produces decoded output. Set endInput when no further input68
* will arrive so truncation can be diagnosed.69
*/70
public fun process(input: NativeByteBuffer, output: NativeByteBuffer, count: Long = input.readableBytes,71
endInput: Boolean = false): CompressionStep = codec.step(Some(input), count, output, output.writableBytes, if (endInput) 2 else 0)72
/**73
* Releases native codec state. Closing does not finish incomplete stream or message data.74
*/75
public override fun close() { codec.close() }76
}78
/**79
* Returns the linked backend version for the requested wire format.80
*/81
public fun compressionBackendVersion(format: CompressionFormat): String {82
@Unsafe { return String.fromCString(compressionVersion(compressionFormatCode(format))) }83
}