Scoop API

scoop:scoop.compression:0.1.0

src/asyncio/sinks.scoop

Selected production source · src/asyncio/sinks.scoop

1package scoop.compression.asyncio
3import scoop.asyncio.*
4import scoop.compression.*
5import scoop.platform.memory.NativeByteBuffer
7/**
8 * A suspending compression sink adapter with bounded buffering. The ordinary constructor borrows
9 * its endpoint; takeOwnership also assumes endpoint close responsibility. I/O waits suspend; codec
10 * computation remains local. Cancellation cleanup waits for active operations. Call finish for
11 * successful completion; close alone does not finish the format.
12 */
13public class AsyncCompressionSink private constructor(private val stream: AsyncCompressionSinkImpl) : AsyncByteSink, AsyncCloseable {
14 public constructor(sink: AsyncByteSink, options: CompressionOptions = CompressionOptions.Zstd(ZstdOptions()),
15 bufferSize: Long = 8192L) : this(AsyncCompressionSinkImpl(sink, currentEventLoop(),
16 compressionIoResources(createCompressionEncoder(options), bufferSize, true), None)) {}
18 /**
19 * Factories that explicitly transfer endpoint cleanup responsibility.
20 */
21 public companion object {
22 /**
23 * Creates an adapter that closes the supplied endpoint during its own cleanup.
24 */
25 public fun <T> takeOwnership(sink: T, options: CompressionOptions = CompressionOptions.Zstd(ZstdOptions()),
26 bufferSize: Long = 8192L): AsyncCompressionSink where T : AsyncByteSink, T : AsyncCloseable =
27 AsyncCompressionSink(AsyncCompressionSinkImpl(sink, currentEventLoop(),
28 compressionIoResources(createCompressionEncoder(options), bufferSize, true), Some(sink)))
29 }
31 /**
32 * The actual input accepted and output delivered so far.
33 */
34 public val totals: CompressionTotals get() = stream.totals
35 /**
36 * The retained terminal failure, or None before failure.
37 */
38 public val failure: Throwable? get() = stream.failure
39 /**
40 * Consumes up to count readable bytes from the input buffer while passing transformed output
41 * downstream.
42 */
43 public override suspend fun writeFrom(buffer: NativeByteBuffer, count: Long): Long = stream.writeFrom(buffer, count)
44 /**
45 * Drains a synchronization point and downstream output without ending input.
46 */
47 public override suspend fun flush() { stream.flush() }
48 /**
49 * Completes the stream and drains final output; decoding also validates that input ended at a
50 * complete format boundary.
51 */
52 public suspend fun finish() { stream.finish() }
53 /**
54 * Releases codec state and closes an endpoint whose ownership was transferred. It does not
55 * force incomplete data to finish.
56 */
57 public override suspend fun close() { stream.close() }
60/**
61 * A suspending decompression sink adapter with bounded buffering. The ordinary constructor borrows
62 * its endpoint; takeOwnership also assumes endpoint close responsibility. I/O waits suspend; codec
63 * computation remains local. Cancellation cleanup waits for active operations. Call finish for
64 * successful completion; close alone does not finish the format.
65 */
66public class AsyncDecompressionSink private constructor(private val stream: AsyncCompressionSinkImpl) : AsyncByteSink, AsyncCloseable {
67 public constructor(sink: AsyncByteSink, options: DecompressionOptions = DecompressionOptions(),
68 bufferSize: Long = 8192L) : this(AsyncCompressionSinkImpl(sink, currentEventLoop(),
69 compressionIoResources(createCompressionDecoder(options), bufferSize, false), None)) {}
71 /**
72 * Factories that explicitly transfer endpoint cleanup responsibility.
73 */
74 public companion object {
75 /**
76 * Creates an adapter that closes the supplied endpoint during its own cleanup.
77 */
78 public fun <T> takeOwnership(sink: T, options: DecompressionOptions = DecompressionOptions(),
79 bufferSize: Long = 8192L): AsyncDecompressionSink where T : AsyncByteSink, T : AsyncCloseable =
80 AsyncDecompressionSink(AsyncCompressionSinkImpl(sink, currentEventLoop(),
81 compressionIoResources(createCompressionDecoder(options), bufferSize, false), Some(sink)))
82 }
84 /**
85 * The actual input accepted and output delivered so far.
86 */
87 public val totals: CompressionTotals get() = stream.totals
88 /**
89 * The retained terminal failure, or None before failure.
90 */
91 public val failure: Throwable? get() = stream.failure
92 /**
93 * Consumes up to count readable bytes from the input buffer while passing transformed output
94 * downstream.
95 */
96 public override suspend fun writeFrom(buffer: NativeByteBuffer, count: Long): Long = stream.writeFrom(buffer, count)
97 /**
98 * Drains a synchronization point and downstream output without ending input.
99 */
100 public override suspend fun flush() { stream.flush() }
101 /**
102 * Completes the stream and drains final output; decoding also validates that input ended at a
103 * complete format boundary.
104 */
105 public suspend fun finish() { stream.finish() }
106 /**
107 * Releases codec state and closes an endpoint whose ownership was transferred. It does not
108 * force incomplete data to finish.
109 */
110 public override suspend fun close() { stream.close() }