How can i use/call Nodejs's Buffer in Angularjs ? i spent many hours in google but i can not find the answer. Thanks for your help.
-
In nodeJs, i wrote some code like: var buffer = new Buffer(9); buffer.writeUInt8(3, 0); buffer.writeUInt32LE(0x00040000, 1); buffer.writeUInt32LE(10, 5); how i can do the same thing in Angulars JS ? Thanks for any reply.V-Q-A NGUYEN– V-Q-A NGUYEN2017-05-26 15:00:11 +00:00Commented May 26, 2017 at 15:00
-
1Buffer is a native Node.js API. It does not exist in standard JSborislemke– borislemke2017-05-26 15:02:47 +00:00Commented May 26, 2017 at 15:02
-
@borislemke: Thanks for your reply. i found this module npmjs.com/package/buffer, can i import and use it in my Angular app ? if yes, how can i do it ?V-Q-A NGUYEN– V-Q-A NGUYEN2017-05-26 15:17:24 +00:00Commented May 26, 2017 at 15:17
-
possible duplicate of stackoverflow.com/questions/8880571/…V-Q-A NGUYEN– V-Q-A NGUYEN2017-05-26 15:23:50 +00:00Commented May 26, 2017 at 15:23
-
I'm not familiar with that module, but if it works as it describes itself, you might as well give it a tryborislemke– borislemke2017-05-26 15:32:04 +00:00Commented May 26, 2017 at 15:32
|
Show 1 more comment
1 Answer
I found the solution. The idea is using ArrayBuffer, DataView of Javascript to make the same thing as Buffer of NodeJS.
For example, in NodeJS, i wrote something:
var buffer = new Buffer(9);
buffer.writeUInt8(3, 0);
buffer.writeUInt32LE(0x00040000, 1);
The corresponding code in Javascript like the following:
var buffer = new ArrayBuffer(9);
var dataview = new DataView(buffer);
dataview.setUint8(0, 3);
dataview.setUint32(1, parseInt('0x00040000'), true);
Hope this helps for anyone have the same problem.
1 Comment
Leonardo Rick
Hi @V-Q-A-NGUYEN , do you know how can I use this method to convert this type of buffer usage?
Buffer.from('some text', 'utf8')