如何读取将给定文本转换为缓冲区,而不是将文本“hello world”添加到给定输入并将 return 最终输出作为缓冲区
How to read convert the given text into buffer than Add the text ‘hello world’ to the given input and return the final output as a buffer
这是我试过的
const Buffer = require('buffer').Buffer
let addBuffer = (text) => {
const textBuffer = Buffer.from(text);
textBuffer.write('hello World ');
return textBuffer;
};
我想添加新字符串,即 'Hello World' 到给定输入的末尾。
我建议为此目的使用 Buffer.concat,这允许您将任意数量的缓冲区连接在一起:
let addBuffer = (text) => {
return Buffer.concat([Buffer.from(text), Buffer.from('hello world')]);
};
console.log(addBuffer('Some text - ').toString("utf8"));
这是我试过的
const Buffer = require('buffer').Buffer
let addBuffer = (text) => {
const textBuffer = Buffer.from(text);
textBuffer.write('hello World ');
return textBuffer;
};
我想添加新字符串,即 'Hello World' 到给定输入的末尾。
我建议为此目的使用 Buffer.concat,这允许您将任意数量的缓冲区连接在一起:
let addBuffer = (text) => {
return Buffer.concat([Buffer.from(text), Buffer.from('hello world')]);
};
console.log(addBuffer('Some text - ').toString("utf8"));