Add FtpControlStream edge case unit tests; fix Span read path heap allocation#51
Merged
sparkeh9 merged 2 commits intocodex/replace-manual-buffer-with-span-typefrom Feb 28, 2026
Merged
Conversation
Co-authored-by: sparkeh9 <5622386+sparkeh9@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Use span-based read helper for control stream
Add FtpControlStream edge case unit tests; fix Span read path heap allocation
Feb 28, 2026
642a5c5
into
codex/replace-manual-buffer-with-span-type
1 check passed
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes per-call heap allocations from FtpControlStream’s single-byte read path and adds coverage for control-stream line parsing behavior, improving both performance and confidence in edge-case handling.
Changes:
- Override
FtpControlStream.ReadByte()to use a cachedbyte[1]buffer instead of allocating on every call. - Add integration tests covering
ReadLineedge cases (empty stream, LF/CRLF termination, incomplete line, null encoding, pre-cancelled token) andReadBytebehavior (null stream, data available, EOF).
Reviewed changes
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/CoreFtp/Infrastructure/Stream/FtpControlStream.cs | Adds cached-buffer ReadByte() override to avoid repeated allocations in the 1-byte read path used by line reading. |
| tests/CoreFtp.Tests.Integration/FtpControlStreamTests/When_reading_control_stream.cs | Adds tests validating ReadLine and ReadByte behavior across key edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sparkeh9
added a commit
that referenced
this pull request
Feb 28, 2026
* Use span-based read helper for control stream * Override ReadByte for control stream * Merge PR #51 Merge Copilot tests for FtpControlStream * Upgrade CoreFTP to .NET 10 and resolve vulnerable dependencies * Fix CI annotations: resolve SYSLIB0039 and CS0108 warnings * Bump version to 2.0.0 and add NuGet publish workflow --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Nick Briscoe <nick.briscoe@razor.co.uk>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stream.ReadByte()in the base class allocates abyte[1]on every call, defeating the goal of theSpan<byte>read path. Additionally, no unit tests existed for the control stream's line-reading logic.Changes
Override
ReadByte()with a cachedreadByteBuffer = new byte[1]field, so the single-byte read path no longer allocates per call:Unit tests added in
FtpControlStreamTests/When_reading_control_stream.csvia aTestStreamsubclass that injects aMemoryStreamasBaseStream, covering:ReadLine: empty stream →null, LF-terminated, CRLF stripping, incomplete line (no LF) →null, null encoding throws, pre-cancelled token throwsReadByte: nullNetworkStream→-1, byte available, EOF →-1✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.