在 Node (node.js) 中有效地进行从 Buffer 到 Buffer 的 Base64 解码
我目前在 noVNC 中有一个 python 和 C 版本的 wsproxy(WebSockets 到普通 TCP 套接字代理)。我想使用 node.js 创建一个 wsproxy 版本。一个关键因素(也是我不只是使用现有节点 WebSocket 代码的原因)是,在 WebSocket 标准具有二进制编码之前,wsproxy 和浏览器/客户端之间的所有流量都必须进行编码(并且 base64 解码/编码快速且简单)在浏览器中)。
Buffer 类型具有 Base64 编码支持,但这是从 Buffer 到字符串,反之亦然。 如何在两个缓冲区之间进行 Base64 编码/解码,而无需先转换为字符串?
约束:
- 直接缓冲区到缓冲区(除非您可以显示缓冲区->字符串- > 缓冲区同样快)。
- 由于节点具有内置的 base64 支持,我想使用它而不是外部模块。
- 在单个缓冲区内进行就地编码/解码是可以接受的。
这里是对 Node 中 Base64 支持的讨论,但据我所知see 没有回答我的问题。
I currently have a python and C version of wsproxy (WebSockets to plain TCP socket proxy) in noVNC. I would like to create a version of wsproxy using node.js. A key factor (and the reason I'm not just using existing node WebSocket code) is that until the WebSocket standard has binary encoding, all traffic between wsproxy and the browser/client must be encoded (and base64 decode/encode is fast and easy in the browser).
Buffer types have base64 encoding support but this is from a Buffer to a string and vice versa. How can I base64 encode/decode between two buffers without having to convert to a string first?
Constraints:
- Direct Buffer to Buffer (unless you can show Buffer->string->Buffer is just as fast).
- Since node has built-in base64 support I would like to use that and not external modules.
- In place encode/decode within a single Buffer is acceptable.
Here is a discussion of base64 support in node, but from what I can see doesn't answer my question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用流来执行此操作,但首先阅读此 有关 UTF-8 解码的博客,因为您可能会遇到类似的问题。我并不是建议您在不需要时进行 UTF-8 编码/解码,而是建议您查看此代码如何处理跨由块边界分隔的多个字节分布的单个字符的问题。
You should be able to do this using streams, but first read through this blog about UTF-8 decoding because you will likely encounter similar issues. I'm not suggesting that you do UTF-8 encode/decode if you don't need it, but that you look at how this code handled the issue of a single character spread across multiple bytes that were separated by a chunk boundary.