Repository navigation
Optimize default file parameters in PipeTarget.ToFile(...) - #333
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates CliWrap’s piping helpers to better control stream lifetimes and to make file piping friendlier for real-time log tailing scenarios (issue #331).
Changes:
- Added
disposeStreamparameter toPipeTarget.ToStream(...)andPipeSource.FromStream(...)to optionally take ownership and dispose the provided stream. - Updated
PipeTarget.ToFile(...)to open files withFileShare.Read(and route copying through the auto-flushing copy helper).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| CliWrap/PipeTarget.cs | Adds disposeStream overloads for ToStream and changes ToFile to allow shared reads while writing. |
| CliWrap/PipeSource.cs | Adds disposeStream overloads for FromStream to optionally dispose the input stream after piping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
disposeStream parameter on ToStream/FromStream and modify ToFile behavior
|
Hmm... do we need a Actually, I don't think creating the FileStream in advance is necessarily a bad thing. (However, this seems to break the API to some extent.) |
Hmm I'm trying to understand which exact change is responsible for that test failure. |
It seems that the file used to be created when calling |
|
Oh wait, here's another problem: if the process fails to start, will Hmm... will it be a good idea to make pipetarget/pipesource IAsyncDisposable? But this would break the existing API... |
Ah I see. That's my bad then, I thought refactoring to call |
@Tyrrrz Please check this as well. If the stream cannot be disposed when the process fails to start, perhaps we shouldn't provide such a misleading overload. After some thought, I realized that adding a |
Yes, that's a good point; I haven't fully considered that the stream may not be disposed of in some cases. Let's downscale to the simplest change we've explore so far: updating the default |
disposeStream parameter on ToStream/FromStream and modify ToFile behaviorToFile behavior
|
Ok I have reverted the changes on ToStream and FromStream |
ToFile behaviorPipeTarget.ToFile(...)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Closes #331