{"id":21898056,"url":"https://github.com/ysden123/scala-csvreader","last_synced_at":"2025-03-22T05:19:32.930Z","repository":{"id":150986040,"uuid":"154704616","full_name":"ysden123/scala-csvreader","owner":"ysden123","description":"Scala CSV file (stream) reader","archived":false,"fork":false,"pushed_at":"2021-04-04T15:48:07.000Z","size":32,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-27T06:11:52.938Z","etag":null,"topics":["csv","file","parser","reader","scala","stream"],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ysden123.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-25T16:37:53.000Z","updated_at":"2021-04-04T12:16:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"98474c16-772f-4e17-b5d5-2be62fbd23cd","html_url":"https://github.com/ysden123/scala-csvreader","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysden123%2Fscala-csvreader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysden123%2Fscala-csvreader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysden123%2Fscala-csvreader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ysden123%2Fscala-csvreader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ysden123","download_url":"https://codeload.github.com/ysden123/scala-csvreader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244908420,"owners_count":20530040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","file","parser","reader","scala","stream"],"created_at":"2024-11-28T14:22:58.000Z","updated_at":"2025-03-22T05:19:32.910Z","avatar_url":"https://github.com/ysden123.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"= scala-csvreader\n\nScala CSV file (stream) reader\n\n== Build status\n\nMaster: image:https://travis-ci.org/ysden123/scala-csvreader.svg?branch=master[Build Status: master,link=https://travis-ci.org/ysden123/scala-csvreader]\n\nDevelop: image:https://travis-ci.org/ysden123/scala-csvreader.svg?branch=develop[Build Status: develop,link=https://travis-ci.org/ysden123/scala-csvreader]\n\n== CsvReader\n\nCsvReader is simple CSV reader with pure Scala.\n\nThe reader supports:\n\n* arbitrary case class for record data\n* file with or without header line\n* setting either continue or stop after error during parsing a record\n* setting different delimiter character\n* error handling\n* record handling\n\n== Usage\n=== Record Data Class\nRecord data class is a case class. For example:\n[source,scala]\n----\ncase class TestData1(i: Int, s: String, d: Double)\n----\nSome parameters may be Option, For example\n[source,scala]\n----\ncase class TestData2(i: Int, s: Option[String], d: Double) {\n  def this(params: Seq[String]) {\n    this(params(0).toInt,\n      if (params(1).isEmpty)\n        None\n      else\n        Some(params(1)),\n      params(2).toDouble\n    )\n  }\n}\n----\nNote in this case the auxiliary constructor should be defined!\n\n=== How to work with CsvReader\n[source,scala]\n----\n    def recordHandler(record:TestData]:Unit={\n    ...\n    }\n\n    def errorHandler(error:String]:Unit={\n    ...\n    }\n\n    CsvReader.reader[TestData](Source.fromFile(\"data.csv\"), recordHandler, errorHandler)\n      .parse()\n----\n\nor\n[source,scala]\n----\n    // Empty record handler\n    def handler(testData: TestData1): Unit = {}\n\n    val list = CsvReader.reader[TestData1](Source.fromResource(\"test-data1.csv\"), handler, errorHandler).toList\n----\n\n=== Use of modificators:\n\n* withDelimiter\n* withContinueOnError\n* withHeaderLine\n* withCustomTransformer\n\n=== How to work with custom transformer\nCustom transformer allows to customize creating an object.\n\nrecordHandler method should be called for each created object.\n\nerrorHandler method should be called for each error during creating object.\n\nExample:\n[source,scala]\n----\n    def transformer(line: Seq[String], recordHandler: TestData1 =\u003e Unit, errorHandler: String =\u003e Unit): TestData1 = {\n        try {\n          val data = TestData1(333, \"test\", 77.12)\n          recordHandler(data)\n          data\n        } catch {\n          case e: Exception =\u003e\n            errorHandler(e.getMessage)\n            throw e\n       }\n    }\n----\n\nSee CsvReaderTest test(\"customTransformer\") and test(\"customTransformer with error\")\n\n== CsvStreamReader\n\nCsvStreamReader is CSV reader with using the Akka stream.\n\nThe reader supports:\n\n* arbitrary case class for record data\n* file with or without header line\n* setting either continue or stop after error during parsing a record\n* setting different delimiter character\n* error handling\n* record handling\n\n== Usage\n=== Record Data Class\nRecord data class is a case class. For example:\n[source,scala]\n----\ncase class TestData1(i: Int, s: String, d: Double)\n----\nSome parameters may be Option, For example\n[source,scala]\n----\ncase class TestData2(i: Int, s: Option[String], d: Double) {\n  def this(params: Seq[String]) {\n    this(params(0).toInt,\n      if (params(1).isEmpty)\n        None\n      else\n        Some(params(1)),\n      params(2).toDouble\n    )\n  }\n}\n----\nNote in this case the auxiliary constructor should be defined!\n\n=== How to work with CsvStreamReader\n[source,scala]\n----\n def recordHandler(record:TestData]:Unit={\n  ...\n }\n\n def errorHandler(error:String]:Unit={\n ...\n }\n\n implicit val actorSystem: ActorSystem = ActorSystem(\"CsvStreamReaderTest\")\n implicit val materializer: ActorMaterializer = ActorMaterializer()\n\n val reader = CsvStreamReader.reader(Source.fromResource(\"test-data1.csv\"), recordHandler, errorHandler)\n\n Await.ready(reader.run(), Duration.Inf)\n source.close()\n actorSystem.terminate()\n----\n\n=== How to get list of items\n[source,scala]\n----\n\n def errorHandler(error:String]:Unit={\n ...\n }\n\n implicit val actorSystem: ActorSystem = ActorSystem(\"CsvStreamReaderTest\")\n implicit val materializer: ActorMaterializer = ActorMaterializer()\n val list = ListBuffer.empty[TestData1]\n\n val reader = CsvStreamReader.reader(Source.fromResource(\"test-data1.csv\"),\n    item =\u003e list += item,\n    errorHandler)\n\n Await.ready(reader.run(), Duration.Inf)\n println(s\"list.length=${list.length}\")\n source.close()\n actorSystem.terminate()\n----\n\n=== Use of modificators:\n\n* withDelimiter\n* withContinueOnError\n* withHeaderLine\n* withCustomTransformer\n\n=== How to work with custom transformer\nSee \"How to work with custom transformer\" for CsvReader (above)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysden123%2Fscala-csvreader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fysden123%2Fscala-csvreader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fysden123%2Fscala-csvreader/lists"}