Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing binary buffer between Node.js 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 combine 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:

  1. Handle the buffer in the same manner in both Server and Browser.

  2. 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.

like image 487
qballer Avatar asked Sep 01 '12 15:09

qballer


People also ask

Can Nodejs be used in a browser?

js is a server-side JavaScript run-time environment. It's open-source, including Google's V8 engine, libuv for cross-platform compatibility, and a core library. Notably, Node. js does not expose a global "window" object, since it does not run within a browser.

How much traffic can node js handle?

js can handle ~15K requests per second, and the vanilla HTTP module can handle 70K rps.

How do I encode a buffer in Node JS?

var buf = new Buffer("Simply Easy Learning", "utf-8"); Though "utf8" is the default encoding, you can use any of the following encodings "ascii", "utf8", "utf16le", "ucs2", "base64" or "hex".


1 Answers

browser-buffer emulates Node's Buffer API in the browser.

It's backed by a Uint8Array, so browser support is sketchy.

like image 178
josh3736 Avatar answered Oct 21 '22 19:10

josh3736