在 Node.js 中,可以使用 Buffer
类的 from
方法将字符串转换为 Buffer
对象。例如:
const str = 'Hello World';
const buf = Buffer.from(str);
console.log(buf); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>
在 Node.js 中,可以使用 Buffer
类的 from
方法将字符串转换为 Buffer
对象。例如:
const str = 'Hello World';
const buf = Buffer.from(str);
console.log(buf); // <Buffer 48 65 6c 6c 6f 20 57 6f 72 6c 64>