https://github.com/sindresorhus/uint8array-extras/blob/cbf24...
Goodbye, Node.js Buffer
31–40 of 103 posts
Re: Goodbye, Node.js Buffer
#32I wonder why you would introduce an extra dependency for the base64 example. It seems more trivial than left pad. https://github.com/sindresorhus/uint8array-extras/blob/cbf24...
Re: Goodbye, Node.js Buffer
#33Re: Goodbye, Node.js Buffer
#34Re: Goodbye, Node.js Buffer
#35TBH I prefer Buffer as an abstraction. Too bad it didn't make it into native JS standard. I can't think of many use cases in JS land were Uint8Array, Uint16Array, Uint32Array, Int8Array would be absolutely necessary. Seems more useful for perf optimizations. For WebAssembly? Surely a plain array of numbers can be used in most cases. The main use case for Buffer IMO is to convert between different formats like Base64,…
Typed arrays are essential for web apps that use WebGL and WebGPU. Being able to send this type of data to run computations on the GPU can give you 1000x speed up. You can see it in action on this WebGL fluid simulator[0] by PavelDoGreat. [0] https://github.com/PavelDoGreat/WebGL-Fluid-Simulation
Re: Goodbye, Node.js Buffer
#36Earlier quoted context omitted.
`Uint8Array.prototype.isPrototypeOf` and `instanceof Uint8Array` do not work across realms (frames, Node.js VM, etc). 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]'; } ```
What do you mean by "across realms"? Is that just another way of saying `Uint8Array.prototype.isPrototypeOf` and `instanceof Uint8Array` are not available in all JS environments? I guess what I'm asking is the definition of a "Javascript Realm" in case I'm thinking it's something different.
Examples of this are frames in the browser and the `vm` module in Node.js.
Re: Goodbye, Node.js Buffer
#37Earlier quoted context omitted.
What do you mean by "across realms"? Is that just another way of saying `Uint8Array.prototype.isPrototypeOf` and `instanceof Uint8Array` are not available in all JS environments? I guess what I'm asking is the definition of a "Javascript Realm" in case I'm thinking it's something different.
https://weizmangal.com/2022/10/28/what-is-a-realm-in-js Examples of this are frames in the browser and the `vm` module in Node.js.
Re: Goodbye, Node.js Buffer
#38I had to deal with binary data in a project recently and all the options made my head spin. File, Blob, Buffer, ArrayBuffer, Uint8Array, and so on. Was very confused on what to use!
- File: Like a Blob, but with additional file-specific properties (e.g., filename).
- ArrayBuffer: Fixed-length raw binary data in JavaScript, not directly accessible.
- Uint8Array: Interface for reading/writing binary data in ArrayBuffer, showing them as 8-bit unsigned integers.
- Buffer: Readable/writable raw binary data container in Node.js (subclass of Uint8Array)
Re: Goodbye, Node.js Buffer
#39But this is an implementation detail, not specified behavior. Changing method behavior in subclasses is a key aspect of inheritance.
Re: Goodbye, Node.js Buffer
#40It's good to see that people care about native JS standards. I'm a bit concerned how Bun seems to be adding their own proprietary APIs to their JS runtime, and can't help feeling that it could be intentional vendor lock-in. Since they are venture backed I'm sure they want some ROI from the project eventually and if they start charging money it will be harder to switch away due to the proprietary APIs without refactor…
It's really because we have some wonderful collaboration between vendors now, and they don't want to have to come up with their own APIs. https://wintercg.org/