Adds source.decodeStringUtf8 for Source[Chunk[Byte]], adapted from fs2
Adds source.encodeUtf8 for Source[String]
Decoding other charsets can be added in the future. It would require a little more complex logic.
Additionally:
Changes .lines to .linesUtf8 and adds .lines(charset)
Changes Chunk's .asText to .asTextUtf8 - I'm not sure if we even want to keep these as public. A Chunk[Byte] may not be a complete set of bytes to decode to a String, and having such methods may encourage users to do source.map(_.asTextUtf8) instead of source.decodeUtf8, where only the second approach is fully safe, unless we are sure that chunks represent complete strings (like lines). These methods are useful internally though.
Some thoughts:
We could also add something like .limitedLinesUtf8, which fails if the limit is exceeded.
Closes https://github.com/softwaremill/ox/issues/138
source.decodeStringUtf8
forSource[Chunk[Byte]]
, adapted from fs2source.encodeUtf8
forSource[String]
Decoding other charsets can be added in the future. It would require a little more complex logic.
Additionally:
.lines
to.linesUtf8
and adds.lines(charset)
Chunk
's.asText
to.asTextUtf8
- I'm not sure if we even want to keep these as public. A Chunk[Byte] may not be a complete set of bytes to decode to a String, and having such methods may encourage users to dosource.map(_.asTextUtf8)
instead ofsource.decodeUtf8
, where only the second approach is fully safe, unless we are sure that chunks represent complete strings (like lines). These methods are useful internally though.Some thoughts:
.limitedLinesUtf8
, which fails if the limit is exceeded.TODO: