缓冲区和迭代
【Buffers and iteration】
Buffer 实例可以使用 for..of 语法进行迭代:
import { Buffer } from 'node:buffer';
const buf = Buffer.from([1, 2, 3]);
for (const b of buf) {
console.log(b);
}
// Prints:
// 1
// 2
// 3const { Buffer } = require('node:buffer');
const buf = Buffer.from([1, 2, 3]);
for (const b of buf) {
console.log(b);
}
// Prints:
// 1
// 2
// 3此外,buf.values()、buf.keys() 和 buf.entries() 方法可用于创建迭代器。
【Additionally, the buf.values(), buf.keys(), and
buf.entries() methods can be used to create iterators.】