purescript-node/purescript-node-buffer

toArrayBuffer

matthewleon opened this issue · 2 comments

There should probably be a way to convert these to ArrayBuffer. It's pretty simple to do: https://stackoverflow.com/questions/8609289/convert-a-binary-nodejs-buffer-to-javascript-arraybuffer

The question it raises is whether that would mean 1) exporting the ArrayBuffer type from this package, 2) adding a dependency to purescript-arraybuffer-types, or 3) moving this functionality somewhere else (or does it exist somewhere else already?)

My feeling is that option 2) makes some sense, though it's breaking.

On further thought, perhaps the smartest way is to add the dependency and export toUint8Array, defined simply as an unsafeCoerce.

On third thought, using unsafeCoerce to get a Uint8Array is unwise because of a couple of subtle differences between the two types, as explained here: https://nodejs.org/docs/latest/api/buffer.html#buffer_buffers_and_typedarray

The initial ArrayBuffer idea should work though.