FileCodec

class FileCodec<T : @Serializable Any>(file: Path, tempFile: Path, json: Json, serializer: KSerializer<T>) : Codec<T>

Constructors

Link copied to clipboard
constructor(file: Path, tempFile: Path, json: Json, serializer: KSerializer<T>)

Functions

Link copied to clipboard
open suspend override fun decode(): T?

Decodes the file to a value. If the file does not exist, null is returned.

Link copied to clipboard
open suspend override fun encode(value: T?)

Encodes the given value to the file. If the value is null, the file is deleted. If the encoding fails, the temp file is deleted. If the encoding succeeds, the temp file is atomically moved to the target file - completing the transaction.