You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,7 +142,7 @@ A `CSVReadder` parses CSV data from a given input (`String`, or `Data`, or file)
142
142
143
143
CSV fields are separated within a row with _field delimiters_ (commonly a "comma"). CSV rows are separated through _row delimiters_ (commonly a "line feed"). You can specify any unicode scalar, `String` value, or `nil` for unknown delimiters.
144
144
145
-
-`escapingStrategy` (default `.doubleQuote`) specify the Unicode scalar used to escape fields.
145
+
-`escapingStrategy` (default `"`) specify the Unicode scalar used to escape fields.
146
146
147
147
CSV fields can be escaped in case they contain priviledge characters, such as field/row delimiters. Commonly the escaping character is a double quote (i.e. `"`), by setting this configuration value you can change it (e.g. a single quote), or disable the escaping functionality.
148
148
@@ -315,11 +315,11 @@ let result = try decoder.decode(CustomType.self, from: data)
315
315
`CSVDecoder` can decode CSVs represented as a `Data` blob, a `String`, or an actual file in the file system.
316
316
317
317
```swift
318
-
let decoder =CSVDecoder { $0.bufferingStrategy= .fulfilled }
318
+
let decoder = CSVDecoder { $0.bufferingStrategy = .assembled }
319
319
let content: [Student] = try decoder([Student].self, from: URL("~/Desktop/Student.csv"))
320
320
```
321
321
322
-
If you are dealing with a big CSV file, it is preferred to used direct file decoding, a `.sequential` or `.fulfilled` buffering strategy, and set*presampling* to false; since then memory usage is drastically reduced.
322
+
If you are dealing with a big CSV file, it is preferred to used direct file decoding, a `.sequential` or `.assembled` buffering strategy, and set *presampling* to false; since then memory usage is drastically reduced.
323
323
324
324
### Decoder configuration
325
325
@@ -367,15 +367,15 @@ let data: Data = try encoder.encode(value)
367
367
The `Encoder`'s `encode()` function creates a CSV file as a `Data` blob, a `String`, or an actual file in the file system.
368
368
369
369
```swift
370
-
let encoder =CSVEncoder { $0.bufferingStrategy=.sequential }
If you are dealing with a big CSV content, it is preferred to use direct file encoding and a `.sequential` or `.fulfilled` buffering strategy, since then memory usage is drastically reduced.
374
+
If you are dealing with a big CSV content, it is preferred to use direct file encoding and a `.sequential` or `.assembled` buffering strategy, since then memory usage is drastically reduced.
375
375
376
376
### Encoder configuration
377
377
378
-
The encoding process can be tweaked by specifying configuration values. `CSVEncoder` accepts the [same configuration values as `CSVWRiter`](#Writer-configuration) plus the following ones:
378
+
The encoding process can be tweaked by specifying configuration values. `CSVEncoder` accepts the [same configuration values as `CSVWriter`](#Writer-configuration) plus the following ones:
379
379
380
380
- `floatStrategy` (default `.throw`) defines how to deal with non-conforming floating-point numbers (e.g. `NaN`).
When a custom type conforms to `Codable`, the type is stating that it has the ability to decode itself from and encode itself to a external representation. Which representation depends on the decoder or encoder chosen. Foundation provides support for [JSON and Property Lists](https://developer.apple.com/documentation/foundation/archives_and_serialization), but the community provide many other formats, such as: [YAML](https://github.com/jpsim/Yams), [XML](https://github.com/MaxDesiatov/XMLCoder), [BSON](https://github.com/OpenKitten/BSON), and CSV (through this library).
422
+
When a custom type conforms to `Codable`, the type is stating that it has the ability to decode itself from and encode itself to a external representation. Which representation depends on the decoder or encoder chosen. Foundation provides support for [JSON and Property Lists](https://developer.apple.com/documentation/foundation/archives_and_serialization) and the community provide many other formats, such as: [YAML](https://github.com/jpsim/Yams), [XML](https://github.com/MaxDesiatov/XMLCoder), [BSON](https://github.com/OpenKitten/BSON), and CSV (through this library).
423
423
424
424
Lets see a regular CSV encoding/decoding usage through `Codable`'s interface. Let's suppose we have a list of students formatted in a CSV file:
Copy file name to clipboardExpand all lines: sources/Codable/Decodable/DecoderConfiguration.swift
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -91,7 +91,7 @@ extension Strategy {
91
91
/// Forward/Backwards decoding jumps are allowed. However, previously requested rows cannot be requested again or an error will be thrown.
92
92
///
93
93
/// This strategy will massively reduce the memory usage, but it will throw an error if a CSV row that was previously decoded is requested from a keyed container.
94
-
casefulfilled
94
+
caseassembled
95
95
/// No rows are kept in memory (except for the CSV row being decoded at the moment)
96
96
/// Forward jumps are allowed, but the rows in-between the jump cannot be decoded.
Copy file name to clipboardExpand all lines: sources/Codable/Encodable/EncoderConfiguration.swift
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -100,20 +100,21 @@ extension Strategy {
100
100
/// All encoded rows/fields are cached and the *writing* only occurs at the end of the encodable process.
101
101
///
102
102
/// *Keyed containers* can be used to encode rows/fields unordered. That means, a row at position 5 may be encoded before the row at position 3. Similar behavior is supported for fields within a row.
103
-
/// - attention: This strategy consumes the largest amount of memory from all the supported options.
103
+
/// - remark: This strategy consumes the largest amount of memory from all the supported options.
104
104
case keepAll
105
105
/// Encoded rows may be cached, but the encoder will keep the buffer as small as possible by writing completed ordered rows.
106
106
///
107
107
/// *Keyed containers* can be used to encode rows/fields unordered. The writer will however consume rows in order.
108
108
///
109
-
/// For example, an encoder starts encoding row 1 and it gets all its fields. The row will get written and no cache for the row is kept. Same situation occurs when the row 2 is encoded.
109
+
/// For example, an encoder starts encoding row 1 and gets all its fields. The row will get written and no cache for the row is kept anymore. Same situation occurs when the row 2 is encoded.
110
110
/// However, the user may decide to jump to row 5 and encode it. This row will be kept in the cache till row 3 and 4 are encoded, at which time row 3, 4, 5, and any subsequent rows will be writen.
111
-
/// - attention: This strategy tries to keep the cache to a minimum, but memory usage may be big if there are holes while encoding rows. Those holes are filled with empty rows at the end of the encoding process.
112
-
case fulfilled
111
+
/// - attention: If no headers are passed during configuration the encoder has no way to know when a row is completed. That is why, the `.keepAll` buffering strategy will be used instead for such a case.
112
+
/// - remark: This strategy tries to keep the cache to a minimum, but memory usage may be big if there are holes while encoding rows/fields. Those holes are filled with empty rows/fields at the end of the encoding process.
113
+
case assembled
113
114
/// Only the last row (the one being written) is kept in memory. Writes are performed sequentially.
114
115
///
115
116
/// *Keyed containers* can be used, but at file-level any forward jump will imply writing empty-rows. At field-level *keyed containers* may still be used for random-order writing.
116
-
/// - attention: This strategy provides the smallest usage of memory from all.
117
+
/// - remark: This strategy provides the smallest usage of memory from all.
0 commit comments