Skip to content
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

fix(node/buffer): make slice be the same as subarray #19481

Merged
merged 3 commits into from
Jun 13, 2023

Conversation

crowlKats
Copy link
Member

No description provided.

@crowlKats crowlKats changed the title fix(node/buffer): make slice be the same as subarray fix(node/buffer): make slice be the same as subarray Jun 13, 2023
const newBuf = this.subarray(start, end);
Object.setPrototypeOf(newBuf, Buffer.prototype);
return newBuf;
return this.subarray(start, end);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Question: Does subarray return a Buffer or a Uint8Array?

Copy link
Member Author

Choose a reason for hiding this comment

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

a Buffer

const newBuf = this.subarray(start, end);
Object.setPrototypeOf(newBuf, Buffer.prototype);
return newBuf;
return this.subarray(start, end);
Copy link
Member

Choose a reason for hiding this comment

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

I think this is wrong. Slice returns a clone while subarray returns a view on the same array.

Copy link
Member Author

@crowlKats crowlKats Jun 13, 2023

Choose a reason for hiding this comment

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

i thought so as well, however, per node docs:

Returns a new Buffer that references the same memory as the original, but offset and cropped by the start and end indices.
This method is not compatible with the Uint8Array.prototype.slice(), which is a superclass of Buffer. To copy the slice, use Uint8Array.prototype.slice().

and node does the same as i am doing here

@crowlKats crowlKats merged commit 92e7287 into denoland:main Jun 13, 2023
10 checks passed
@crowlKats crowlKats deleted the fix_buffer_slice branch June 13, 2023 19:26
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.

None yet

3 participants