This repository has been archived by the owner on Feb 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Typeful reader API #45
Labels
Milestone
Comments
Here's the code for retrieving the file from the "resources" or the "${user.home}/.kotools/csv" folders: data class CsvFile(val file: File)
/**
* Returns the [CSV file][CsvFile] matching the given [path], or returns `null`
* if no file was found from the `"resources"` and the
* `"${user.home}/.kotools/csv"` folders.
*
* The `.csv` extension is **optional** in the [path].
* For example, calling this function with `"folder/file.csv"` produces the same
* output as calling it with `"folder/file"`.
*/
fun csvFileOrNull(path: NotBlankString): CsvFile? {
val filePath: NotBlankString = path.takeIf { it.value.endsWith(".csv") }
?: NotBlankString("$path.csv")
val file: File? = ClassLoader.getSystemResource(filePath.value)
?.let { File(it.path) }
?: System.getProperty("user.home")
.let(::Path)
.resolve(".kotools")
.resolve("csv")
.resolve(filePath.value)
.takeIf { it.exists() }
?.toFile()
return file?.let(::CsvFile)
} |
LVMVRQUXL
added a commit
that referenced
this issue
Nov 21, 2022
Declarations of this function and its dependencies are internal for now.
LVMVRQUXL
added a commit
that referenced
this issue
Nov 22, 2022
LVMVRQUXL
added a commit
that referenced
this issue
Nov 22, 2022
For converting a record to a custom type, we could use the serialization pattern (see kotlinx.serialization library). |
LVMVRQUXL
added a commit
that referenced
this issue
Nov 22, 2022
LVMVRQUXL
added a commit
that referenced
this issue
Nov 23, 2022
… a CSV file" This reverts commit a40bab1.
LVMVRQUXL
added a commit
that referenced
this issue
Nov 23, 2022
… a file" This reverts commit 61d5444.
LVMVRQUXL
added a commit
that referenced
this issue
Nov 23, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
Description
Based on #14, introduce a new reader API in the
kotools.csv
package for reading CSV files and deprecate the old one in theio.github.kotools.csv
package.Dependencies
This issue needs the following ones to be done:
Checklist
Work in progress
section in changelog.The text was updated successfully, but these errors were encountered: