There is an issue of how to share buffers between node.js and the browser containing binary data. I'm pretty happy with Socket.io as a transport layer but the issue is that there is no porting of the Buffer class for the browser. Not something I can find anyways
I've also came across binary.js and I was wondering if there is a good way to bine them having the socket.io as the transport layer and the Binary.js as the data medium. I also saw this question, which is kind of on topic but doesn't really resolve the issue.
I know socket.io added binary support but I haven't found any documentation on the topic.
Update:
It seems that binary.js will not be the solution. The basic requirement that I want is to share the same capabilities that Buffer has in node with the browser.
My needs consist of two things:
Handle the buffer in the same manner in both Server and Browser.
support Binary data.
I will probably use Array Buffer.
Edit: Since node.js run over V8 you can use ArrayBuffer. It seems as if the issue is solved. Yet, from what I know, node people decided that it's a good idea to create a buffer module and manage it in the C bindings they created (from a talk given by Ryan Dahl). I think this has to do with how buffering is done over the network. This means ArrayBuffer is still not a good data medium to share between server and browser.
There is an issue of how to share buffers between node.js and the browser containing binary data. I'm pretty happy with Socket.io as a transport layer but the issue is that there is no porting of the Buffer class for the browser. Not something I can find anyways
I've also came across binary.js and I was wondering if there is a good way to bine them having the socket.io as the transport layer and the Binary.js as the data medium. I also saw this question, which is kind of on topic but doesn't really resolve the issue.
I know socket.io added binary support but I haven't found any documentation on the topic.
Update:
It seems that binary.js will not be the solution. The basic requirement that I want is to share the same capabilities that Buffer has in node with the browser.
My needs consist of two things:
Handle the buffer in the same manner in both Server and Browser.
support Binary data.
I will probably use Array Buffer.
Edit: Since node.js run over V8 you can use ArrayBuffer. It seems as if the issue is solved. Yet, from what I know, node people decided that it's a good idea to create a buffer module and manage it in the C bindings they created (from a talk given by Ryan Dahl). I think this has to do with how buffering is done over the network. This means ArrayBuffer is still not a good data medium to share between server and browser.
Share Improve this question edited May 23, 2017 at 12:16 CommunityBot 11 silver badge asked Sep 1, 2012 at 15:34 qballerqballer 2,1112 gold badges22 silver badges41 bronze badges 7- 1 I don't understand what exactly the problem is. What functionality are you exactly interested in that does not exist in the browser? – Benjamin Gruenbaum Commented Sep 1, 2012 at 18:47
- My needs consist of two things: 1. Handle the buffer in the same manner in both Server and Browser. 2. Support Binary data. – qballer Commented Sep 1, 2012 at 18:53
-
1
@BenjaminGruenbaum: The problem is not that functionality isn't available in the browser, it's that the functionality that is available in the browser (typed arrays) isn't available in
node.js
. He doesn't want to have to write all his code twice. – David Schwartz Commented Sep 18, 2012 at 21:56 - Hi @DavidSchwartz thanks for promoting this question. I've added some details to clarify the Array Buffer issue. – qballer Commented Sep 20, 2012 at 11:19
- 1 Nope, ArrayBuffer will only e out with IE10. There is still a performance issue with buffering a data structure from the V8. That is why node.js run the buffer module outside of V8 – qballer Commented Sep 20, 2012 at 15:55
2 Answers
Reset to default 9 +125browser-buffer emulates Node's Buffer
API in the browser.
It's backed by a Uint8Array
, so browser support is sketchy.
JavaScript's built in strings use wide characters internally. So they can easily store a value from 0 to 255 in each character position. This is a JavaScript language feature, so it should work the same in a browser or in node.js
.
You can use charCodeAt
to extract the value of a particular position in a string and fromCharCode
to create a character (that you can add to a string) with a value from 0 to 255.
You can use the various string functions to manipulate data in this form. You can create constants using JavaScript string constants like this "\x00\x12\x34\x56"
.