-
-
Notifications
You must be signed in to change notification settings - Fork 0
Consolidate the Reader and Writer side #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a40d308 to
60080fd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR consolidates the Reader and Writer implementations by refactoring the Reader to internally use the Writer component. The previous implementation used a buffered reader approach with marker detection, while the new implementation uses a pipe-based architecture where data flows through a Writer that demultiplexes text and binary streams into separate pipes, which are then processed by goroutines.
Key changes:
- Refactored
NewReaderto returnio.ReadCloser(previouslyio.Reader) and use a goroutine-based architecture with pipes - Renamed the constructor from
NewtoNewReaderfor consistency - Added mutex protection in tests to handle concurrent access to shared slices from blob handlers
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| reader.go | Complete architectural rewrite using Writer internally with goroutines and pipes instead of buffered marker detection |
| reader_test.go | Updated to use NewReader constructor, added mutex protection for concurrent blob handling, added Close() calls, and added new benchmark |
| writer_test.go | Simplified test setup by using standard io.Pipe() instead of custom pipeReadWriteCloser type, added new benchmark |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
87f0d75 to
16f28c3
Compare
16f28c3 to
176e4f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 4 out of 5 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for b.Loop() { | ||
| r := New(&buf, bh) | ||
| r := NewReader(&buf, bh) | ||
| _, err := io.Copy(io.Discard, r) | ||
| if err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| err = r.Close() | ||
| if err != nil { | ||
| b.Fatal(err) | ||
| } | ||
| } |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benchmark reuses the same buffer in each iteration without resetting it. After the first iteration, the buffer is fully consumed (EOF), so subsequent iterations will immediately return EOF without actually benchmarking the reader logic. The buffer should be reset or recreated for each iteration to ensure accurate benchmarking.
| // The reader passed to it receives the blob. Any non-consumed data will be discarded. | ||
| handleBlob func(id uint32, r io.Reader) error | ||
| } | ||
| g, _ := errgroup.WithContext(context.Background()) |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errgroup is created with context.Background() and the returned context is discarded. This means there's no way to cancel the goroutines if needed. If the caller abandons reading without calling Close(), the goroutines will continue running. Consider using the context or documenting that Close() must be called to properly clean up resources.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.