Commit 0a60523
fix: Don't dispose source stream by default in ToMemoryStreamAsync (#1724)
* fix: Don't dispose source stream by default in ToMemoryStreamAsync
Fixes #1534
The ToMemoryStreamAsync extension method was unexpectedly disposing the input
stream after copying, which is surprising behavior for an extension method.
Additionally, behavior was inconsistent - MemoryStream inputs were returned
as-is (not disposed), while other streams were disposed.
Changes:
- Add disposeSource parameter (defaults to false)
- Reset output MemoryStream position to 0 for immediate reading
- Also reset MemoryStream input position to 0 for consistency
- Updated tests to pass disposeSource: true to prevent resource leaks
Callers who want the old disposal behavior can pass disposeSource: true.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Handle disposeSource consistently for MemoryStream inputs
When disposeSource=true and input is a MemoryStream, now copies to a new
MemoryStream before disposing the original. This ensures consistent behavior
regardless of input stream type.
Before: MemoryStream inputs were returned directly, ignoring disposeSource
After: MemoryStream inputs are copied when disposeSource=true, then disposed
* fix: Use await using for MemoryStream in tests
Use await using declaration for MemoryStream results in tests for
consistency and to ensure proper disposal patterns.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* docs: Add detailed remarks for ToMemoryStreamAsync breaking change
Document:
- Breaking change from previous behavior (now defaults to no disposal)
- MemoryStream optimization behavior
- Caller responsibility for disposing returned stream
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 828a48a commit 0a60523
2 files changed
Lines changed: 40 additions & 8 deletions
File tree
- src/ModularPipelines/Extensions
- test/ModularPipelines.UnitTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
11 | 26 | | |
12 | | - | |
13 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
14 | 33 | | |
15 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
16 | 37 | | |
17 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
18 | 44 | | |
19 | 45 | | |
20 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
21 | 49 | | |
22 | 50 | | |
23 | 51 | | |
| |||
26 | 54 | | |
27 | 55 | | |
28 | 56 | | |
29 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
30 | 61 | | |
| 62 | + | |
31 | 63 | | |
32 | 64 | | |
33 | 65 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
0 commit comments