Skip to content

Conversation

@bep
Copy link
Owner

@bep bep commented Dec 12, 2025

No description provided.

Copy link

Copilot AI left a 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 NewReader to return io.ReadCloser (previously io.Reader) and use a goroutine-based architecture with pipes
  • Renamed the constructor from New to NewReader for 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.

@bep bep force-pushed the feat/consolidate branch 2 times, most recently from 87f0d75 to 16f28c3 Compare December 12, 2025 12:45
Copy link

Copilot AI left a 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.

Comment on lines 358 to 368
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)
}
}
Copy link

Copilot AI Dec 12, 2025

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.

Copilot uses AI. Check for mistakes.
// 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())
Copy link

Copilot AI Dec 12, 2025

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.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bep bep closed this Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants