feat: allow streaming, line-buffered input and output#287
feat: allow streaming, line-buffered input and output#287corneliusroemer wants to merge 1 commit intochmln:masterfrom
Conversation
01b4dd7 to
3bc6bc4
Compare
3bc6bc4 to
c5aa590
Compare
CosmicHorrorDev
left a comment
There was a problem hiding this comment.
Just some initial feedback to get things stared
| */ | ||
| pub flags: Option<String>, | ||
|
|
||
| #[arg(short = 'l', long = "line-buffered", default_value_t = false)] |
There was a problem hiding this comment.
| #[arg(short = 'l', long = "line-buffered", default_value_t = false)] | |
| #[arg(short, long, default_value_t)] |
Nit: we can use clap's "magic values" for all of these
| Source::from_stdin() | ||
| }; | ||
|
|
||
| if options.line_buffered && sources == Source::from_stdin() { |
There was a problem hiding this comment.
Currently this silently ignores the --line-buffered flag when running with files which seems pretty problematic
| handle | ||
| .write_all(replaced.as_ref()) | ||
| .expect("Error writing to standard output"); | ||
| handle.flush().expect("Error flushing output"); |
There was a problem hiding this comment.
| handle | |
| .write_all(replaced.as_ref()) | |
| .expect("Error writing to standard output"); | |
| handle.flush().expect("Error flushing output"); | |
| handle.write_all(replaced.as_ref())?; | |
| handle.flush()?; |
Failing to write is a pretty normal operation that we handle with the normal failure paths currently
| .write_all(replaced.as_ref()) | ||
| .expect("Error writing to standard output"); | ||
| handle.flush().expect("Error flushing output"); | ||
| buffer.clear(); |
There was a problem hiding this comment.
I'd prefer if this buffer.clear() was moved right before the .read_line(). Forgetting to clear a buffer that you're reusing is a super common mistake that's annoying to debug
|
2 cents:
|
Very likely people are, yes. Or anyone who wants to match over multiple lines
You can get a slice from it and wrap it in an |
Multi-line matching isn't tied to full reads, at least theoretically. Practically it might be, yes. But "line buffered" should be implementation detail. Something like I'm curious if a temp file would be useful here.
TIL |
Allowing for line buffering inputs opens the door for streaming
To support streaming reads from stdin. I was looking through |
|
Did a little test on (Excuse my "unificationism" XD) |
The major shortcoming of
sdright now is that it doesn't support streaming stdin to stdout, instead, all input is read into memory which meanssdcan't be used for bigger-than-memory tasks.This PR is based on @vtronko's work in #100 but adapted for current main.
It's a bit of a graft and rough around the edges, no validation of multi-line mode switch off etc, but it's a proof of concept and already useful (roughly 3x faster than sed).
Resolves: