See the entire conversation

What tools do people use for working with binary in JS across Node.js and the browser that avoids a full Buffer polyfill in the browser? I have not found a good solution yet.
15 replies and sub-replies as of Apr 10 2019

Typed arrays + Dataview work everywhere
Almost all Node.js programs and API's expect a Buffer
buffers are Uint8Arrays though, so theoretically you could only wrap in a buffer in node?
Webpack for browser code. Which packages a polyfill for you. I’d pull my hair out if I had to work with DataViews and TypedArrays directly, but this solution allows me to forget about it.
That polyfill is way too bug tho, especially when I only ever use 3 methods :(
I understand and feel ya, but for my lazy ass it’s the lowest friction option.
It's what I'm doing now until I find a better option.
Let us know, would love to see what you find. :)
Was thinking about it to when working on client side code for @NEARProtocol. We seriously lack JS packaging tools that can operate on method level. Of course language is dynamic, but you should be able to configure exclusion pattern, etc.
The only problem is encoding... A wrapper around arraybuffer to support encoding would be cool but the line between that and buffer it self is thin.
What about TextEncoder/TextDecoder APIs? Also I’m meaning to, but never got around, make a lib that exposes all the Buffer.prototype methods as static functions that take Uint8Array’s so only things that need to encode/decode use it but keep API web compatible
That's what i have been thinking about with @lidelOrg but textenconder doesn't cover all the use cases but helps a lot. The bigger problem is the ergonomics of a interface that supports node buffer and a web wrapper arraybuffer thing like this.
Let’s create one
Let's done it 🚀