As in below code, I can write base64 encoded stream into a file but I want to assign the base64 encoded string to a variable rather than creating a file so that I can use it for the purpose I want. How can I assign response.pipe(base64.encode());
to a variable as base64 encoded string ? I am using base64-stream
to encode incoming stream.
const request = xero.call('GET', `/Invoices/${invoiceId}`);
request.setHeader('Accept', 'application/pdf');
request.on('response', async (response) => {
const data = response.pipe(base64.encode());
const file = fs.createWriteStream(`${invoiceId}.txt`);
data.pipe(file);
});
request.end();
via Shaolin
No comments:
Post a Comment