Repository navigation
Conversation
I mean't using a more specific overload of Line 191 in 447da95
I don't see any reason not to... do you? |
|
Sure! If we welcome such change, I have no problem with it. I have updated the code. Below are the settings for each parameter:
|
There was a problem hiding this comment.
Pull request overview
This PR updates PipeTarget.ToFile to support the use case from #331 (real-time log tailing) by allowing callers to control the underlying FileStream settings (mode/share/buffer/options) and flushing behavior.
Changes:
- Expanded
PipeTarget.ToFileto acceptFileMode,FileShare,bufferSize,FileOptions, andautoFlush. - Switched implementation from
File.Create(...)to constructingFileStreamdirectly to apply the requested settings.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public static PipeTarget ToFile( | ||
| string filePath, | ||
| FileMode mode = FileMode.Create, | ||
| FileShare share = FileShare.Read, | ||
| int bufferSize = 4096, | ||
| FileOptions options = FileOptions.None, | ||
| bool autoFlush = true |
| using var target = new FileStream(filePath, mode, FileAccess.Write, share, bufferSize, options); | ||
| await origin.CopyToAsync(target, autoFlush, cancellationToken).ConfigureAwait(false); |
There was a problem hiding this comment.
Hmmm... I found no reason to use ToAsyncDisposable here.
|
I haven't noticed that there is a formatting requirements. I have modified the code. |
|
Do you think we can avoid creating a new overload and just update the existing method, by replacing the option-less |
|
Hmm... I'm not quite sure what concerns are currently preventing us from providing these options. I think sometimes we might need Append instead of just Create. In some cases, we might also need FileShare to be ReadWrite (but in others it seems less safe), and FileOptions.WriteThrough might be necessary in some very important scenarios (but often it might be overkill and not encouraged). Theoretically speaking, we should always offer greater customizability? |
|
I think you can get sufficient customizability via |
Actually, in that case, the file stream can't be disposed timely. (Sometimes it's not convenient to manage it yourself.) I think maybe adding a parameter like
This might not just be a mirror; instead we genuinely need such features. For example, |
Yes, I was thinking about that too. Let's add Perhaps we should also update Would that solve the customizability concerns? |
|
Ok sure. I have updated the code. Additionally, I've merged the two existing |
|
@yueyinqiu unfortunately we can't merge those methods because it breaks binary backward compatibility |
|
I've created a new PR #333 instead |
Closes #331
I am not entirely sure if I correctly understand the meaning of 'update the default file settings'. I think it is worth noting that avoiding caching may potentially lead to a loss in performance. Additionally, I referred to the current implementation of
ToStream(bool autoFlush), and I wonder if we might want to avoid breaking binary compatibility?Therefore, I have opted to simply add a new overload for now; if you believe the original
ToFilecould be modified directly, we can adjust it further.