Readable

interface Readable : Closeable

Acts as a proxy to an actual data source by handling read access.

Inheritors

Functions

Link copied to clipboard
fun Readable.asInputStream(range: LongRange? = null, wrapError: (ReadError) -> IOException = { ReadException(it) }): InputStream

Wraps a Readable into an InputStream.

Link copied to clipboard

Returns a new Readable accessing the same data but not owning them.

Link copied to clipboard
fun Readable.buffered(contentLength: Long? = null, bufferSize: Int = DEFAULT_BUFFER_SIZE): Readable

Wraps this resource into a buffer to improve reading performances.

Link copied to clipboard
abstract fun close()

Closes this object and releases any resources associated with it. If the object is already closed then invoking this method has no effect.

Link copied to clipboard
abstract suspend fun length(): Try<Long, ReadError>

Returns data length from metadata if available, or calculated from reading the bytes otherwise.

Link copied to clipboard
abstract suspend fun read(range: LongRange? = null): Try<ByteArray, ReadError>

Reads the bytes at the given range.

Link copied to clipboard
inline suspend fun <R> Readable.readDecodeOrElse(decode: (value: ByteArray) -> Try<R, DecodeError>, recover: (ReadError) -> R): R
inline suspend fun <R> Readable.readDecodeOrElse(decode: (value: ByteArray) -> Try<R, DecodeError>, recoverRead: (ReadError) -> R, recoverDecode: (DecodeError.Decoding) -> R): R
Link copied to clipboard
inline suspend fun <R> Readable.readDecodeOrNull(decode: (value: ByteArray) -> Try<R, DecodeError>): R?
Link copied to clipboard
inline suspend fun Readable.readOrElse(recover: (ReadError) -> ByteArray): ByteArray