Skip to content

Bun Support #416

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

Closed
wants to merge 2 commits into from
Closed

Bun Support #416

wants to merge 2 commits into from

Conversation

Darker-Ink
Copy link

So I'm using bun for one of my projects. I'm also using cassandra-driver. These are a few issues which cause the driver to not work with bun. I've gone ahead and fixed them.

I tested this on bun version 1.0.6, With that I also tested with node v16.20.2+

Changing how we connect to the net client so runtimes like bun will work (tested this on 1.0.6)
In bun, for some reason when concating buffers if the length is set to undefined, bun returns a empty buffer. This fixes that (still works in node, tested on bun v1.06 and node v16.20.2+)
@Darker-Ink
Copy link
Author

I've also already signed the datastax CLA

@SiyaoIsHiding SiyaoIsHiding requested a review from Copilot June 5, 2025 14:45
Copy link

@Copilot 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 introduces fixes to support Bun in a project that utilizes cassandra-driver by addressing incompatibilities in buffer concatenation and connection setup.

  • Updated Buffer.concat fallback in lib/streams.js to handle an undefined bodyLength.
  • Modified net and tls connection initialization in lib/connection.js to use configuration objects and proper port conversion.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/streams.js Uses a fallback to compute the total buffer length when bodyLength is missing.
lib/connection.js Updates the net and tls connection methods to use an object-based configuration.
Comments suppressed due to low confidence (1)

lib/connection.js:177

  • [nitpick] It may be helpful to add a brief comment on why the connection options are being restructured into an object and the port is being parsed, to provide context for future maintainers.
this.netClient.connect({ host: this.address, port: parseInt(this.port, 10) }, function connectCallback() {

@@ -289,7 +289,7 @@ Parser.prototype.addFrameBuffer = function (frameInfo, item) {
*/
Parser.prototype.getFrameBuffer = function (frameInfo, item) {
frameInfo.buffers.push(item.chunk);
Copy link
Preview

Copilot AI Jun 5, 2025

Choose a reason for hiding this comment

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

Consider adding a comment to explain the fallback logic for the bodyLength computation to improve maintainability and ease future code reviews.

Suggested change
frameInfo.buffers.push(item.chunk);
frameInfo.buffers.push(item.chunk);
// If frameInfo.bodyLength is undefined, fall back to summing the lengths of all buffers.
// This ensures we correctly compute the total length of the concatenated buffers.

Copilot uses AI. Check for mistakes.

@Darker-Ink
Copy link
Author

These changes should no longer be needed for latest versions of bun

@Darker-Ink Darker-Ink closed this Jun 5, 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.

1 participant