All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.seiko.imageloader.component.fetcher.Base64Fetcher.kt Maven / Gradle / Ivy

There is a newer version: 1.9.0
Show newest version
package com.seiko.imageloader.component.fetcher

import com.seiko.imageloader.component.mapper.Base64Image
import com.seiko.imageloader.model.extraData
import com.seiko.imageloader.model.mimeType
import com.seiko.imageloader.option.Options
import okio.Buffer

class Base64Fetcher private constructor(
    private val data: Base64Image,
) : Fetcher {
    override suspend fun fetch(): FetchResult {
        return FetchResult.Source(
            source = Buffer().apply {
                write(data.content)
            },
            extra = extraData {
                mimeType(data.contentType)
            },
        )
    }

    class Factory : Fetcher.Factory {
        override fun create(data: Any, options: Options): Fetcher? {
            if (data !is Base64Image) return null
            return Base64Fetcher(data)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy