-
Notifications
You must be signed in to change notification settings - Fork 48
Open
Description
byline with keepEmptyLines: true behaves slightly differently than most line readers I've encountered, including node's readline module. I created sample.txt by running:
echo foo> sample.txt
echo bar>> sample.txt
echo>> sample.txt
echo and baz>> sample.txtbyline will return 5 chunks for this file (or 3 with keepEmptyLines: false). The readline sample returns four lines:
Line from file: foo
Line from file: bar
Line from file:
Line from file: and baz
As does this C# program:
using System;
using System.IO;
class Program
{
static void Main(string[] args)
{
using (var stream = new FileStream("sample.txt", FileMode.Open))
using (var reader = new StreamReader(stream))
{
string line;
while (null != (line = reader.ReadLine()))
{
Console.WriteLine($"Line from file: {line}");
}
}
}
}(perl -ne 'print "Line from file: $_";' sample.txt also prints 4 lines, but with newlines still attached.)
If byline's current behavior is considered by design, it would be nice if there was a new option to ignore the trailing EOL in a stream. This would make byline more of a drop-in replacement for readline.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels