ipld / js-block

IPLD Block Interface
6 stars 3 forks source link

Use TypedArrays instead of Node.js Buffers #3

Open vmx opened 4 years ago

vmx commented 4 years ago

I think we should build or JS libraries (especially new ones) with Browser primitives and not Node.js ones. Hence I suggest using TypedArrays instead of Node.js Buffers.

I know that's a bigger issue and there were already lengthy discussions about it. So if this isn't the right place for the issue, feel free to open a new one/link to another one.

I just fear that if we don't start using TypedArrays rather soon, Node.js Buffers will bleed up to all the other stuff we build on top and we will never change it.

mikeal commented 4 years ago

I agree, which is why I wrote https://github.com/mikeal/bytesish but when I was writing the latest PR here I realized that I don’t expose the faster allocUnsafe call so I’m going to need to improve it before I can use it in my most recent PR.

But yes, I think this is where we should push in general. In fact, there’s some fundamental changes we should make to get-codec and how this library uses it in order to trim the bundle size as well.

mikeal commented 4 years ago

Oh, for the record, I think that we should avoid using Buffer directly but we should still return Buffer instances in Node.js. This is easily doable with bytesish.native() but is a little different than “using typearrays instead of Node.js Buffers.”