Goodbye, Node.js Buffer
11–20 of 103 posts
Re: Goodbye, Node.js Buffer
#12Re: Goodbye, Node.js Buffer
#13I find buffer useful for its conversion functions to/from different encodings, e.g., `Buffer.from(data, 'hex')` or `Buffer.toString('base64')`. Is there a good way to do this with `Uint8Array`?
Re: Goodbye, Node.js Buffer
#14I find buffer useful for its conversion functions to/from different encodings, e.g., `Buffer.from(data, 'hex')` or `Buffer.toString('base64')`. Is there a good way to do this with `Uint8Array`?
Polyfill Buffer.
Re: Goodbye, Node.js Buffer
#15Does JavaScript's security model let you effectively sandbox scripts running in the same context from each other? If not, then why does this matter?
Re: Goodbye, Node.js Buffer
#16Buffer's `slice` is nice to have in many cases though. The pool makes it generally faster. And `allocUnsafe` is a great feature! I like Buffer.
Re: Goodbye, Node.js Buffer
#17I find buffer useful for its conversion functions to/from different encodings, e.g., `Buffer.from(data, 'hex')` or `Buffer.toString('base64')`. Is there a good way to do this with `Uint8Array`?
I also provide a package to make the transition easier: https://github.com/sindresorhus/uint8array-extras (Feel free to copy-paste the code if you don't want another dependency)
Re: Goodbye, Node.js Buffer
#18> Buffer also comes with additional caveats. For instance, Buffer#slice() creates a mutable segment linked to the original Buffer, while Uint8Array#slice() creates an immutable copy, resulting in possible unpredictable behavior. I can see how the Buffer behavior here would be preferable in cases where performance is important or memory constrained environments.
Re: Goodbye, Node.js Buffer
#19I find buffer useful for its conversion functions to/from different encodings, e.g., `Buffer.from(data, 'hex')` or `Buffer.toString('base64')`. Is there a good way to do this with `Uint8Array`?
You can use ‘atob’ and ‘btoa’ functions for some of that.
Re: Goodbye, Node.js Buffer
#20I agree with using Uint8Array (although it's really ArrayBuffer that's the key difference), but what is up with the author using an NPM package to do something as trivial as checking if an object is a Uint8Array? `Uint8Array.prototype.isPrototypeOf` should be perfectly adequate and doesn't involve adding an attack vector to your application.
Feel free to copy-paste the function to your own code base if you don't want the dependency:
``` const objectToString = Object.prototype.toString;
export function isUint8Array(value) { return value && objectToString.call(value) === '[object Uint8Array]'; } ```