在Node.js服务器和浏览器之间共享二进制缓冲区 [英] Sharing binary buffer between Node.js server and Browser
问题描述
如何在node.js和包含二进制数据的浏览器之间共享缓冲区存在问题。我很高兴 Socket.io 作为传输层,但问题是没有移植缓冲类。不是我能找到的东西
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
我也遇到过二进制文件。 js 和我想知道是否有一种很好的方法可以将socket.io作为传输层并将Binary.js作为数据媒体进行组合。我也看到了这个问题,这是一个主题但不真的解决了这个问题。
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.
我知道socket.io添加了二进制支持,但我没有找到关于该主题的任何文档。
I know socket.io added binary support but I haven't found any documentation on the topic.
更新:
似乎binary.js不是解决方案。我想要的基本要求是与浏览器共享Buffer在节点中具有的相同功能。
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.
我的需求包含两件事:
-
处理缓冲区在服务器和浏览器中以相同的方式。
Handle the buffer in the same manner in both Server and Browser.
支持二进制数据。
我可能会使用数组缓冲区。
I will probably use Array Buffer.
编辑:
由于node.js在V8上运行,因此您可以使用ArrayBuffer。似乎问题已经解决了。然而,据我所知,节点人员认为创建一个缓冲模块并在他们创建的C绑定中管理它是一个好主意(来自Ryan Dahl的讲话)。我认为这与如何通过网络进行缓冲有关。这意味着ArrayBuffer仍然不是在服务器和浏览器之间共享的良好数据媒体。
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.
推荐答案
浏览器缓冲区在浏览器中模拟Node的缓冲区
API。
browser-buffer emulates Node's Buffer
API in the browser.
它由 Uint8Array
,所以浏览器支持是粗略的。
这篇关于在Node.js服务器和浏览器之间共享二进制缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!