Buffer

Prior to the introduction of TypedArray, the JavaScript language had no mechanism for reading or manipulating streams of binary data. The Buffer class was introduced as part of the Node.js API to enable interaction with octet streams in TCP streams, file system operations, and other contexts.

补充对Tcp的知识:

引言中已经阐述了TCP传输必须约定数据传输格式——否则,无法区分相邻数据包边界。一般典型的TCP传输约定格式如下:

  • 数据包 = 数据包体长度(data size) + 数据包体(data)。

假设:要通过TCP发送的数据为data=”abcdef”,那么数据包体长度就是strlen(data)=6,而数据包体就是”abcdef”,所以整个数据包就是(6abcdef)

Instances of the Buffer class are similar to arrays of integers but correspond to fixed-sized, raw memory allocations outside the V8 heap. The size of the Buffer is established when it is created and cannot be changed.

Buffer实例在创建时就被固定大小,无法改变,类似于整型数组

The Buffer class is within the global scope, making it unlikely that one would need to ever use require('buffer').Buffer.

全局作用域内,直接用

你可能感兴趣的:(Buffer)