缓冲区与迭代器
可以使用 for..of 语法迭代 Buffer 实例:
const buf = Buffer.from([1, 2, 3]);
for (const b of buf) {
console.log(b);
}
// 打印:
// 1
// 2
// 3此外,buf.values()、buf.keys() 和 buf.entries() 方法可用于创建迭代器。
Buffer instances can be iterated over using for..of syntax:
const buf = Buffer.from([1, 2, 3]);
for (const b of buf) {
console.log(b);
}
// Prints:
// 1
// 2
// 3Additionally, the buf.values(), buf.keys(), and
buf.entries() methods can be used to create iterators.