scoop:scoop.compression:0.1.0
src/sinks.scoop
Selected production source · src/sinks.scoop
1
package scoop.compression3
import scoop.platform.io.ByteSink4
import scoop.platform.memory.NativeByteBuffer6
/**7
* A synchronous compression sink adapter with bounded buffering. The ordinary constructor borrows8
* its endpoint; takeOwnership also assumes endpoint close responsibility. Call finish for9
* successful completion; close alone does not finish the format.10
*/11
public class CompressionSink private constructor(private val stream: SyncCompressionSink) : ByteSink, Closeable {12
public constructor(sink: ByteSink, options: CompressionOptions = CompressionOptions.Zstd(ZstdOptions()),13
bufferSize: Long = 8192L) : this(SyncCompressionSink(sink,14
compressionIoResources(createCompressionEncoder(options), bufferSize, true), None)) {}16
/**17
* Factories that explicitly transfer endpoint cleanup responsibility.18
*/19
public companion object {20
/**21
* Creates an adapter that closes the supplied endpoint during its own cleanup.22
*/23
public fun <T> takeOwnership(sink: T, options: CompressionOptions = CompressionOptions.Zstd(ZstdOptions()),24
bufferSize: Long = 8192L): CompressionSink where T : ByteSink, T : Closeable =25
CompressionSink(SyncCompressionSink(sink,26
compressionIoResources(createCompressionEncoder(options), bufferSize, true), Some(sink)))27
}29
/**30
* The actual input accepted and output delivered so far.31
*/32
public val totals: CompressionTotals get() = stream.totals33
/**34
* The retained terminal failure, or None before failure.35
*/36
public val failure: Throwable? get() = stream.failure37
/**38
* Consumes up to count readable bytes from the input buffer while passing transformed output39
* downstream.40
*/41
public override fun writeFrom(buffer: NativeByteBuffer, count: Long): Long = stream.writeFrom(buffer, count)42
/**43
* Drains a synchronization point and downstream output without ending input.44
*/45
public override fun flush() { stream.flush() }46
/**47
* Completes the stream and drains final output; decoding also validates that input ended at a48
* complete format boundary.49
*/50
public fun finish() { stream.finish() }51
/**52
* Releases codec state and closes an endpoint whose ownership was transferred. It does not53
* force incomplete data to finish.54
*/55
public override fun close() { stream.close() }56
}58
/**59
* A synchronous decompression sink adapter with bounded buffering. The ordinary constructor60
* borrows its endpoint; takeOwnership also assumes endpoint close responsibility. Call finish for61
* successful completion; close alone does not finish the format.62
*/63
public class DecompressionSink private constructor(private val stream: SyncCompressionSink) : ByteSink, Closeable {64
public constructor(sink: ByteSink, options: DecompressionOptions = DecompressionOptions(),65
bufferSize: Long = 8192L) : this(SyncCompressionSink(sink,66
compressionIoResources(createCompressionDecoder(options), bufferSize, false), None)) {}68
/**69
* Factories that explicitly transfer endpoint cleanup responsibility.70
*/71
public companion object {72
/**73
* Creates an adapter that closes the supplied endpoint during its own cleanup.74
*/75
public fun <T> takeOwnership(sink: T, options: DecompressionOptions = DecompressionOptions(),76
bufferSize: Long = 8192L): DecompressionSink where T : ByteSink, T : Closeable =77
DecompressionSink(SyncCompressionSink(sink,78
compressionIoResources(createCompressionDecoder(options), bufferSize, false), Some(sink)))79
}81
/**82
* The actual input accepted and output delivered so far.83
*/84
public val totals: CompressionTotals get() = stream.totals85
/**86
* The retained terminal failure, or None before failure.87
*/88
public val failure: Throwable? get() = stream.failure89
/**90
* Consumes up to count readable bytes from the input buffer while passing transformed output91
* downstream.92
*/93
public override fun writeFrom(buffer: NativeByteBuffer, count: Long): Long = stream.writeFrom(buffer, count)94
/**95
* Drains a synchronization point and downstream output without ending input.96
*/97
public override fun flush() { stream.flush() }98
/**99
* Completes the stream and drains final output; decoding also validates that input ended at a100
* complete format boundary.101
*/102
public fun finish() { stream.finish() }103
/**104
* Releases codec state and closes an endpoint whose ownership was transferred. It does not105
* force incomplete data to finish.106
*/107
public override fun close() { stream.close() }108
}