how to create a buffer with out Buffer in javascript

163 Views Asked by At

I looking to write some code to run on a espruino ( a programable micro chip that works with javascript) to work as a bluetooth remote, I have it working perfectly in node on my laptop using node and relying heavenly on "Buffer.from" however I can't use the Buffer module on the espruino.

I've tried varies ways of using ArrayBuffer etc but can't find any thing that works can any one recommend a work around ?

also i do need to do the converting with in the script so if there a way to store a buffer that would work

Any help would be greatly appreciated as it driving me nuts

Cheers

James

1

There are 1 best solutions below

0
On

Espruino doesn't have Buffer built in, but it does have Typed arrays and also DataView.

You should just be able to create a typed array with new Uint8Array([....]) that'll do what you need. In fact there's also a E.toUint8Array function that basically takes whatever you throw at it and converts it into a Uint8Array.

If you could give a bit more info about what you require (are you making a Bluetooth -> Infrared remote, or using USB HID?) then I'd probably be able to help a lot more.