Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

convert stream to string javascript

function streamToString (stream) {
  const chunks = [];
  return new Promise((resolve, reject) => {
    stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
    stream.on('error', (err) => reject(err));
    stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
  })
}

const result = await streamToString(yourStreamHere)
//Do something with the result
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #convert #stream #string #javascript
ADD COMMENT
Topic
Name
1+1 =