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

Support a no-Buffer mode #1047

Closed
fabiospampinato opened this issue Aug 22, 2023 · 6 comments
Closed

Support a no-Buffer mode #1047

fabiospampinato opened this issue Aug 22, 2023 · 6 comments

Comments

@fabiospampinato
Copy link

Node's Buffer can be somewhat painful to work with sometimes, because they can be passed to functions accepting Uint8Arrays, but while they provide an extension of the same interface they actually work differently in some cases, for example when calling .toString() on them.

As such I try not to deal with Buffers if I can help it, but I see better-sqlite3 defaults to returning me Buffers.

Would it be possible to add some kind of flag that opts into using standard Uint8Arrays instead?

@JoshuaWise
Copy link
Member

Interesting... I've used Uint8Arrays for front-end or isomorphic code, but never for node-specific projects. Practically every single core API in Node.js uses Buffers. How do you accomplish anything without using them?

@fabiospampinato
Copy link
Author

What do you mean? I can pass a Uint8Array to anything that accepts a Uint8Array, which includes everything I want to pass Uint8Arrays to, like fs.writeFile and whatever else I use support Uint8Arrays. I can't think of a single thing I use that accepts Buffers but not Uint8Arrays.

@JoshuaWise
Copy link
Member

Sure, but every core API such as fs.readFile provides a Buffer, with no way of requesting a Uint8Array.

@fabiospampinato
Copy link
Author

APIs like fs.readFile don't necessarily return a buffer if you don't need one, like maybe want you want is a string, in which case the problem doesn't exist. If you need a buffer but you don't want a Buffer buffer then you can just convert a Buffer into a Uint8Array.

I'm not exactly sure what your point is, but avoiding Buffer buffers has more pros than cons for me, hence why I'd like to be able to get Uint8Arrays from better-sqlite3.

@Prinzhorn
Copy link
Contributor

Related nodejs/node#41588

@mceachen
Copy link
Member

The confusion and support for this switch will be non-trivial. I think we should only consider switching to Uint8Arrays if Node itself makes the decision to make this large switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants