Skip to content

Commit 2db5f56

Browse files
committed
Adopts Combine's TopLevelEncoder/Decoder
1 parent f7f96ca commit 2db5f56

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

CodableCSV.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'CodableCSV'
3-
s.version = '0.5.4'
3+
s.version = '0.5.5'
44
s.summary = "Read and write CSV files row-by-row or through Swift's Codable interface."
55

66
s.homepage = 'https://github.com/dehesa/CodableCSV'

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

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

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

5252
```
53-
pod 'CodableCSV', '~> 0.5.4'
53+
pod 'CodableCSV', '~> 0.5.5'
5454
```
5555

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

79-
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.
79+
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.
8080

8181
- Complete input parsing.
8282

sources/declarative/decodable/Decoder.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,11 @@ extension CSVDecoder {
9696
return LazySequence(source: source)
9797
}
9898
}
99+
100+
#if canImport(Combine)
101+
import Combine
102+
103+
extension CSVDecoder: TopLevelDecoder {
104+
public typealias Input = Data
105+
}
106+
#endif

sources/declarative/encodable/Encoder.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ extension CSVEncoder {
6262
try sink.completeEncoding()
6363
}
6464
}
65+
66+
#if canImport(Combine)
67+
import Combine
68+
69+
extension CSVEncoder: TopLevelEncoder {
70+
public typealias Output = Data
71+
}
72+
#endif

sources/imperative/reader/ReaderAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private extension CSVReader {
229229
/// - parameter stream: The stream to be parsed.
230230
/// - parameter configuration: Recipe detailing how to parse the CSV data (i.e. encoding, delimiters, etc.).
231231
/// - throws: `CSVError<CSVReader>` exclusively.
232-
private convenience init(stream: InputStream, configuration: Configuration) throws {
232+
convenience init(stream: InputStream, configuration: Configuration) throws {
233233
assert(!configuration.presample && stream.streamStatus == .notOpen)
234234
stream.open()
235235

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

260260
var result: [[String]] = .init()

0 commit comments

Comments
 (0)