Reputation: 14236
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,
Upvotes: 5
Views: 5601
Reputation: 113916
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.
Upvotes: 8