Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Maybe I'm mistaken, but I seem to recall node Buffer offers views as typed arrays, so a copy wouldn't be necessary.
I mean, this must be some typescript shenanigan or so because why would JavaScript even complain if you pass in something that essentially quacks like a duck? -
Or not, rather it seems one more of the inconsistencies between browsers and node. Nothing (in the case of buffer) a polyfill can't solve.
-
Uint8Array & ArrayBuffer weren´t defined when Node was initially released, they had to come up with some low-level API to manipulate binary files. For ex the docs of Node v0.12 make no mention of these and explain buffer as a standalone API (https://nodejs.org/docs/...) whereas later docs define it as a subclass.
To your concern, the second example at https://nodejs.org/api/buffer.html/... should convert the buffer to a typed array without causing memory overhead -
hitko31451y@webketje The commit is from February this year, therefore everything you said is completely irrelevant. They could literary just do "if (val instanceof Uint8Array) return val;" and everything would work perfectly fine. But nooooo, gotta make an overengineered piece of crap and force users to mess around with pointless hacks to get it working. And why bother properly explaining such a weird decision on a massively popular project with hundreds of contributors and official support from one of the largest software foundations?
https://github.com/mozilla/pdf.js/...
Buffer *is* Uint8Array (there's literary "Buffer extends Uint8Array" in NodeJS lib/internal/buffer.js), why would there be a need to wrap it? But thanks to this bullshit error, I have to copy my buffer to a plain Uint8Array, quote, "which essentially means creating a copy of the data and thus increasing memory usage."
rant