缓冲区和迭代
\Buffers and iteration
可以使用 for..of 语法迭代 Buffer 实例:
\Buffer instances can be iterated over using for..of syntax:
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.