DefaultFileSaver

inline fun <T> DefaultFileSaver(path: String, crossinline write: suspend (data: T?, toPath: String) -> Unit, crossinline read: suspend (fromPath: String) -> T?, crossinline recover: suspend (Exception) -> T?): Saver<T>

A Saver implementation that saves the given state to a file in a specified path

  • You still need to provide your own write and read functions for this overload. Use FileSaver and CompressedFileSaver if you want to save already serialized state.

  • This saver creates the necessary directories and files if not present and writes to file in an atomic way using a Mutex.

  • If null is passed to Saver.save, it will delete the file, but not the directory.

  • The writes to the file cannot be canceled to prevent saving partial data.

inline fun <T> DefaultFileSaver(dir: String, fileName: String, crossinline write: suspend (data: T?, to: Path) -> Unit, crossinline read: suspend (from: Path) -> T?, crossinline recover: suspend (Exception) -> T?): Saver<T>

A Saver implementation that saves the given state to a file in a specified dir and fileName.

  • You still need to provide your own write and read functions for this overload. Use FileSaver and CompressedFileSaver if you want to save already serialized state.

  • This saver creates the necessary dir and file if not present and writes to file in an atomic way using a mutex.

  • If null is passed to Saver.save, it will delete the file, but not the directory.

  • The writes to the file cannot be canceled to prevent saving partial data.