New Issue: I/O module: adjustments to readline

19495, "mppf", "I/O module: adjustments to readline", "2022-03-18T15:09:16Z"

Today we have this:

proc channel.readline(arg: [] uint(8), out numRead: int,
                      start = _, amount = _): bool throws
proc channel.readline(ref arg: ?t) : bool throws
  • First of these reads into a uint(8) array and the second reads into a string or bytes
  • Having both readln and readline is confusing

Proposal:

  • With proposed ‘readln’ changes, ‘readln(string)’ or ‘readln(bytes)’
    reads a whole line with the default Decoder (TODO see other issue)
  • But, still need other functions to specify a max len; work with other data types; work with non-default Decoder
proc reader.readUtf8Line(maxCodepoints: int = -1, maxBytes: int = -1) : string throws
proc reader.readBytesLine(maxBytes: int = -1) : bytes throws
proc reader.readLineData(data, maxBytes: int) : int throws
  • All of these store the newline in the result, unless EOF was encountered before the newline (following Python)
  • string/bytes returning functions return “” on EOF and use -1 to mean unlimited length (following Python)
  • readLineData accepts same types as writeData and returns number of bytes read, and 0 on EOF
  • These functions will ignore the channel’s Decoder