Scoop API

scoop:scoop.compression:0.1.0

src/sources.scoop

Selected production source · src/sources.scoop

1package scoop.compression
3import scoop.platform.io.ByteSource
4import scoop.platform.memory.NativeByteBuffer
6/**
7 * A synchronous compression source adapter with bounded buffering. The ordinary constructor
8 * borrows its endpoint; takeOwnership also assumes endpoint close responsibility. Reading to EOF
9 * completes format validation; early close does not.
10 */
11public class CompressionSource private constructor(private val stream: SyncCompressionSource) : ByteSource, Closeable {
12 public constructor(source: ByteSource, options: CompressionOptions = CompressionOptions.Zstd(ZstdOptions()),
13 bufferSize: Long = 8192L) : this(SyncCompressionSource(source,
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(source: T, options: CompressionOptions = CompressionOptions.Zstd(ZstdOptions()),
24 bufferSize: Long = 8192L): CompressionSource where T : ByteSource, T : Closeable =
25 CompressionSource(SyncCompressionSource(source,
26 compressionIoResources(createCompressionEncoder(options), bufferSize, true), Some(source)))
27 }
29 /**
30 * The actual input accepted and output delivered so far.
31 */
32 public val totals: CompressionTotals get() = stream.totals
33 /**
34 * The retained terminal failure, or None before failure.
35 */
36 public val failure: Throwable? get() = stream.failure
37 /**
38 * Produces up to count transformed bytes into the writable buffer region. EOF completes the
39 * format; short reads are permitted.
40 */
41 public override fun readInto(buffer: NativeByteBuffer, count: Long): Long = stream.readInto(buffer, count)
42 /**
43 * Releases codec state and closes an endpoint whose ownership was transferred. It does not
44 * force incomplete data to finish.
45 */
46 public override fun close() { stream.close() }
49/**
50 * A synchronous decompression source adapter with bounded buffering. The ordinary constructor
51 * borrows its endpoint; takeOwnership also assumes endpoint close responsibility. Reading to EOF
52 * completes format validation; early close does not.
53 */
54public class DecompressionSource private constructor(private val stream: SyncCompressionSource) : ByteSource, Closeable {
55 public constructor(source: ByteSource, options: DecompressionOptions = DecompressionOptions(),
56 bufferSize: Long = 8192L) : this(SyncCompressionSource(source,
57 compressionIoResources(createCompressionDecoder(options), bufferSize, false), None)) {}
59 /**
60 * Factories that explicitly transfer endpoint cleanup responsibility.
61 */
62 public companion object {
63 /**
64 * Creates an adapter that closes the supplied endpoint during its own cleanup.
65 */
66 public fun <T> takeOwnership(source: T, options: DecompressionOptions = DecompressionOptions(),
67 bufferSize: Long = 8192L): DecompressionSource where T : ByteSource, T : Closeable =
68 DecompressionSource(SyncCompressionSource(source,
69 compressionIoResources(createCompressionDecoder(options), bufferSize, false), Some(source)))
70 }
72 /**
73 * The actual input accepted and output delivered so far.
74 */
75 public val totals: CompressionTotals get() = stream.totals
76 /**
77 * The retained terminal failure, or None before failure.
78 */
79 public val failure: Throwable? get() = stream.failure
80 /**
81 * Produces up to count transformed bytes into the writable buffer region. EOF completes the
82 * format; short reads are permitted.
83 */
84 public override fun readInto(buffer: NativeByteBuffer, count: Long): Long = stream.readInto(buffer, count)
85 /**
86 * Releases codec state and closes an endpoint whose ownership was transferred. It does not
87 * force incomplete data to finish.
88 */
89 public override fun close() { stream.close() }