Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 18, 2025

Update functions to accept ReadableStreamDefaultReader

Plan:

  • Update countRows function to accept ReadableStreamDefaultReader<Uint8Array> instead of ReadableStream<Uint8Array>
  • Update chunk function to accept ReadableStreamDefaultReader<Uint8Array> instead of ReadableStream<Uint8Array>
  • Remove getReader() calls and releaseLock() calls from both functions
  • Update all tests to create a reader from the stream before passing to functions
  • Update README examples to show getting a reader first
  • Rebuild and verify all tests pass
  • Run linter to ensure code quality
  • Refactor to use async iteration (for await...of) instead of while(true) loops

Changes Made:

  • Modified countRows() to accept ReadableStreamDefaultReader<Uint8Array> as the first parameter
  • Modified chunk() to accept ReadableStreamDefaultReader<Uint8Array> as the first parameter
  • Removed try/finally blocks and releaseLock() calls since the reader is no longer owned by the functions
  • Updated test helper from createStreamFromString() to createReaderFromString() to return a reader
  • Updated all 22 tests to use the new helper function
  • Updated README documentation with new API and examples
  • Added makeReaderIterable() helper function to enable async iteration over readers
  • Refactored both functions to use for await...of loops instead of manual while(true) with reader.read()
  • All tests pass (22/22)
  • Linter passes with no errors
Original prompt

Update the functions to take a ReadableStreamDefaultReader instead of a ReadableStream. Be sure to update tests and the README.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Update functions to accept ReadableStreamDefaultReader Accept ReadableStreamDefaultReader instead of ReadableStream Nov 18, 2025
Copilot AI requested a review from nzakas November 18, 2025 22:11
@nzakas nzakas changed the title Accept ReadableStreamDefaultReader instead of ReadableStream fix: Accept ReadableStreamDefaultReader instead of ReadableStream Nov 21, 2025
src/index.js Outdated
try {
while (true) {
const { done, value } = await reader.read();
while (true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot let's use async iteration (for await...of) instead of while(true);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added a makeReaderIterable() helper function to enable async iteration and refactored to use for await...of (ca57ec6).

src/index.js Outdated
}
}
}
while (true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot let's use async iteration here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Both functions now use for await...of with the makeReaderIterable() helper (ca57ec6).

@nzakas nzakas marked this pull request as ready for review November 21, 2025 21:31
Copilot AI requested a review from nzakas November 21, 2025 21:39
@nzakas nzakas closed this Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants