-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read File node in a line at a time mode returns an extra, blank line. #3913
Comments
Node-RED is written in javascript (not awk, C or perl) and the way javascript spilts a file on When we split the input into lines we add a If this stream is fed into a join node then it will rejoin them correctly and output the "file" correctly. However if sent to a file out node set to append lines and add a new line then it results in a file with an extra linefeed at the end. So IMHO there are two possible related fixes/enhancements, to the file out node...
Note: -in both of these - we would rely on the fact that msg.parts existed correctly - if not present then we would append (or not) the newline as configured by the setting. I believe the first option could be considered a bug fix and while a small change in behaviour I think it is not unreasonable and does better reflect the intended behaviour. The second is definitely breaking so should be only considered for a major upgrade. |
I just can't make sense of this interpretation.
|
and wc -l on a file with just "one line" - returns 0 as the answer so maybe need to fix that as well ? |
Current Behavior
GIven this datafile, each line terminated by
\n
(on Linux $ printf "%s\n%s\n" "ONE" "TWO" > testdata)ONE
TWO
Read File a message per line emits 3 messages "ONE, "TWO" and ""
This is contrary to some other programming languages, at least on Linux. eg C getline() will retrieve 2 lines, so do interpreted languages such as awk and perl.
If the second new line is removed ($ printf "%s\n%s" "ONE" "TWO" > testdata), read File now emits 2 messages "ONE" and "TWO", while the C, awk, perl etc versions still report 2 lines.
NB wc -l is different, it simply counts
\n
characters.If you pass the 3 messages to a Write File node, add
\n
to each line, the resulting file now has two new lines at the end.Expected Behavior
Both versions of the test data file, with and without a final new line character, should result in two messages, in accordance with other programmatic ways of counting lines.
The final, empty string message is the error
Steps To Reproduce
See discussion on NR forum
Example flow
No response
Environment
The text was updated successfully, but these errors were encountered: