简体   繁体   中英

Buffer Octet Stream in NodeJs

I am novice in NodeJs and i have read about Buffer but not clear.

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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