//readium-shared/org.readium.r2.shared.fetcher/TransformingResource
TransformingResource¶
[androidJvm]\ abstract class TransformingResource(resource: Resource, cacheBytes: Boolean = true) : ProxyResource
Transforms the bytes of resource on-the-fly.
If you set cacheBytes to false, consider providing your own implementation of length to avoid unnecessary transformations.
Warning: The transformation runs on the full content of resource, so it's not appropriate for large resources which can't be held in memory.
Constructors¶
TransformingResource | [androidJvm] fun TransformingResource(resource: Resource, cacheBytes: Boolean = true) |
Types¶
Name | Summary |
---|---|
Companion | [androidJvm] object Companion |
Functions¶
Name | Summary |
---|---|
close | [androidJvm] open suspend override 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. |
length | [androidJvm] open suspend override fun length(): ResourceTry<Long> Returns data length from metadata if available, or calculated from reading the bytes otherwise. |
link | [androidJvm] open suspend override fun link(): Link Returns the link from which the resource was retrieved. |
read | [androidJvm] open suspend override fun read(range: LongRange?): ResourceTry<ByteArray> Reads the bytes at the given range. |
readAsBitmap | [androidJvm] open suspend fun readAsBitmap(): ResourceTry<Bitmap> Reads the full content as a Bitmap. |
readAsJson | [androidJvm] open suspend fun readAsJson(): ResourceTry<JSONObject> Reads the full content as a JSON object. |
readAsString | [androidJvm] open suspend fun readAsString(charset: Charset? = null): ResourceTry<String> Reads the full content as a String. |
readAsXml | [androidJvm] open suspend fun readAsXml(): ResourceTry<ElementNode> Reads the full content as an XML document. |
toString | [androidJvm] open override fun toString(): String |
transform | [androidJvm] abstract suspend fun transform(data: ResourceTry<ByteArray>): ResourceTry<ByteArray> |
Properties¶
Name | Summary |
---|---|
file | [androidJvm] open override val file: File? Direct file to this resource, when available. |
Extensions¶
Name | Summary |
---|---|
buffered | [androidJvm] fun Resource.buffered(resourceLength: Long? = null, size: Long = BufferingResource.DEFAULT_BUFFER_SIZE): BufferingResource Wraps this resource in a BufferingResource to improve reading performances. |
cached | [androidJvm] fun Resource.~~cached~~(): Resource Creates a cached resource wrapping this resource. |
fallback | [androidJvm] fun Resource.fallback(fallbackResourceFactory: (Resource.Exception) -> Resource): Resource Falls back to alternative resources when the receiver fails. [androidJvm] fun Resource.fallback(fallbackResource: Resource): Resource Falls back to the given alternative resource when the receiver fails. |
synchronized | [androidJvm] fun Resource.synchronized(): SynchronizedResource Wraps this resource in a SynchronizedResource to protect the access from multiple threads. |