-
Notifications
You must be signed in to change notification settings - Fork 285
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
Reliable way to strip BOM from a stream #221
Comments
I think so, yes. If you want to make sure it stays that way, working the above script into a test file for Node core seems feasible? ;) |
@addaleax Thank you. I am not sure, how a user can present such a test. The team makes it clear that BOM stripping is for userland. And it seems that nodejs/node#7337 makes such a test code currently unreliable. |
I wouldn’t worry about nodejs/node#7337; realistically, I wouldn’t expect fs streams to touch the file contents in the future, so the BOM will remain included. I’m thinking of something like this: A test fixture containing data like
(no BOM) and a test script like const input = fs.createReadStream('testfile', { encoding: 'utf8' });
const lines = [];
input.once('readable', () => {
assert.strictEqual(input.read(1), 'a');
rl.createInterface({
input,
}).on('line', (line) => {
lines.push(line);
}).on('close', () => {
assert.deepStrictEqual(lines, ['bc', 'def', 'ghi', 'jkl', 'mno', 'pqr']);
});
}); plus things like As a side note, I don’t know if that’s applicable to your situation, but |
@addaleax Making tests is a completely terra incognita for me now. I am not familiar with API nor with file/directory structure. Maybe I could do something like that hereafter, when I know more, but not in the near future, unfortunately. And thank you again for the |
https://github.com/nodejs/node/blob/master/doc/guides/writing_tests.md might be pretty helpful. Also, I’d be glad to help you find your way around, and generally you can always go to #node-dev on freenode for questions. |
@addaleax Thank you) I shall try. |
Sometimes it is necessary to preprocess some initial bit of a stream data before giving the entire stream to the main processing function. Sometimes this bit should be extracted from the stream before the main processing; sometimes it should be returned to the stream. This test checks an order of stream modes, methods and events for a possible preprocessing algorithm. Stream BOM stripping is selected as a use case. See nodejs/help#221 as the prehistory. PR-URL: #7741 Reviewed-By: Anna Henningsen <[email protected]>
Sometimes it is necessary to preprocess some initial bit of a stream data before giving the entire stream to the main processing function. Sometimes this bit should be extracted from the stream before the main processing; sometimes it should be returned to the stream. This test checks an order of stream modes, methods and events for a possible preprocessing algorithm. Stream BOM stripping is selected as a use case. See nodejs/help#221 as the prehistory. PR-URL: #7741 Reviewed-By: Anna Henningsen <[email protected]>
Sometimes it is necessary to preprocess some initial bit of a stream data before giving the entire stream to the main processing function. Sometimes this bit should be extracted from the stream before the main processing; sometimes it should be returned to the stream. This test checks an order of stream modes, methods and events for a possible preprocessing algorithm. Stream BOM stripping is selected as a use case. See nodejs/help#221 as the prehistory. PR-URL: #7741 Reviewed-By: Anna Henningsen <[email protected]>
Sometimes it is necessary to preprocess some initial bit of a stream data before giving the entire stream to the main processing function. Sometimes this bit should be extracted from the stream before the main processing; sometimes it should be returned to the stream. This test checks an order of stream modes, methods and events for a possible preprocessing algorithm. Stream BOM stripping is selected as a use case. See nodejs/help#221 as the prehistory. PR-URL: #7741 Reviewed-By: Anna Henningsen <[email protected]>
Sometimes it is necessary to preprocess some initial bit of a stream data before giving the entire stream to the main processing function. Sometimes this bit should be extracted from the stream before the main processing; sometimes it should be returned to the stream. This test checks an order of stream modes, methods and events for a possible preprocessing algorithm. Stream BOM stripping is selected as a use case. See nodejs/help#221 as the prehistory. PR-URL: #7741 Reviewed-By: Anna Henningsen <[email protected]>
Till recently I've used this way (this demo script reads and outputs itself line by line):
However, it makes me uneasy that each iteration except the first one should increment and compare the
lineNumber
in vain. So I've come to this solution:However, now I doubt if this flow is reliable. Could it somehow mess up the stream internal mechanics? Is this sequence of stream modes and methods safe?
The text was updated successfully, but these errors were encountered: