5
hitko
281d

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."

Comments
  • 0
    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?
  • 0
    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.
  • 1
    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
  • 0
    @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?
  • 0
    Well the only thing I can add is yet another completely irrelevant comment
Add Comment