简体   繁体   English

NodeJ中的缓冲区八位字节流

[英]Buffer Octet Stream in NodeJs

I am novice in NodeJs and i have read about Buffer but not clear. 我是NodeJ的新手,但我已经了解了Buffer但不清楚。

Some examples:- 一些例子:-

1) var buffer = new Buffer(12);
2) var buffer = new Buffer([12,54,89]);
3) var buffer = new Buffer("Confusing about Buffer", "utf-8");

Here my queries are, 这是我的查询

  • What is the Buffer and what is the way to define/implement. 什么是缓冲区,什么是定义/实现的方法。
  • What is meaning of above examples. 以上示例的含义是什么。

In javascript, strings are not binary safe. 在javascript中,字符串不是二进制安全的。 There are certain characters that are illegal in strings. 某些字符在字符串中是非法的。

This of course makes it very difficult to process binary data such as images or mp3 files since all I/O in javascript deal with strings. 当然,这使得处理二进制数据(例如图像或mp3文件)非常困难,因为javascript中的所有I / O都处理字符串。

The solution that the node developers implemented is Buffers. 节点开发人员实现的解决方案是缓冲区。 Think of buffers as strings for binary data (and remember, text is a subset of binary data). 将缓冲区视为二进制数据的字符串(请记住,文本是二进制数据的子集)。

As for your specific questions, the answer to your second question answers your first question: the example code you posted are examples of how to define buffers . 至于您的特定问题,第二个问题的答案回答了第一个问题: 您发布的示例代码是有关如何定义缓冲区的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM