Skip to content

Commit

Permalink
Adopts Combine's TopLevelEncoder/Decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
dehesa committed Apr 28, 2020
1 parent f7f96ca commit 2db5f56
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CodableCSV.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'CodableCSV'
s.version = '0.5.4'
s.version = '0.5.5'
s.summary = "Read and write CSV files row-by-row or through Swift's Codable interface."

s.homepage = 'https://github.com/dehesa/CodableCSV'
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

- Imperative CSV reader/writer (row-by-row and/or field-by-field).
- Declarative `Codable` encoder/decoder and lazy row decoder.
- Support multiple inputs/outputs: `String`s, `Data` blobs, and `URL`s.
- Support numerous string encodings and Byte Order Markers (BOM).
- Extensive configuration: delimiters, escaping scalar, trim strategy, presampling, codable strategies, etc.
- Support multiple inputs/outputs: `String`s, `Data` blobs, `URL`s, and `Stream`s (commonly used for `stdin`).
- Support numerous string encodings and [Byte Order Markers](https://en.wikipedia.org/wiki/Byte_order_mark) (BOM).
- Extensive configuration: delimiters, escaping scalar, trim strategy, codable strategies, presampling, etc.
- [RFC4180](https://tools.ietf.org/html/rfc4180) compliant with default configuration and CRLF (`\r\n`) row delimiter.
- Multiplatform support with no dependencies.

Expand All @@ -39,7 +39,7 @@ You can choose to add the library through SPM or Cocoapods:
let package = Package(
/* Your package name, supported platforms, and generated products go here */
dependencies: [
.package(url: "https://github.com/dehesa/CodableCSV.git", from: "0.5.4")
.package(url: "https://github.com/dehesa/CodableCSV.git", from: "0.5.5")
],
targets: [
.target(name: /* Your target name here */, dependencies: ["CodableCSV"])
Expand All @@ -50,7 +50,7 @@ You can choose to add the library through SPM or Cocoapods:
- [Cocoapods](https://cocoapods.org).

```
pod 'CodableCSV', '~> 0.5.4'
pod 'CodableCSV', '~> 0.5.5'
```

</p></details>
Expand All @@ -76,7 +76,7 @@ The following types provide imperative control on how to read/write CSV data.
<ul>
<details><summary><code>CSVReader</code>.</summary><p>

A `CSVReader` parses CSV data from a given input (`String`, or `Data`, or file) and returns CSV rows as a `String`s array. `CSVReader` can be used at a _high-level_, in which case it parses an input completely; or at a _low-level_, in which each row is decoded when requested.
A `CSVReader` parses CSV data from a given input (`String`, `Data`, `URL`, or `InputStream`) and returns CSV rows as a `String`s array. `CSVReader` can be used at a _high-level_, in which case it parses an input completely; or at a _low-level_, in which each row is decoded when requested.

- Complete input parsing.

Expand Down
8 changes: 8 additions & 0 deletions sources/declarative/decodable/Decoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ extension CSVDecoder {
return LazySequence(source: source)
}
}

#if canImport(Combine)
import Combine

extension CSVDecoder: TopLevelDecoder {
public typealias Input = Data
}
#endif
8 changes: 8 additions & 0 deletions sources/declarative/encodable/Encoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ extension CSVEncoder {
try sink.completeEncoding()
}
}

#if canImport(Combine)
import Combine

extension CSVEncoder: TopLevelEncoder {
public typealias Output = Data
}
#endif
4 changes: 2 additions & 2 deletions sources/imperative/reader/ReaderAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private extension CSVReader {
/// - parameter stream: The stream to be parsed.
/// - parameter configuration: Recipe detailing how to parse the CSV data (i.e. encoding, delimiters, etc.).
/// - throws: `CSVError<CSVReader>` exclusively.
private convenience init(stream: InputStream, configuration: Configuration) throws {
convenience init(stream: InputStream, configuration: Configuration) throws {
assert(!configuration.presample && stream.streamStatus == .notOpen)
stream.open()

Expand All @@ -254,7 +254,7 @@ private extension CSVReader {
/// - parameter reader: The `CSVReader` used for parsing a CSV input.
/// - throws: `CSVError<CSVReader>` exclusively.
/// - returns: Structure containing all CSV rows and optionally a the CSV headers.
private static func decode(with reader: CSVReader) throws -> FileView {
static func decode(with reader: CSVReader) throws -> FileView {
let lookup = try reader.headers.lookupDictionary(onCollision: Error._invalidHashableHeader)

var result: [[String]] = .init()
Expand Down

0 comments on commit 2db5f56

Please sign in to comment.