Convert a stream to string?

Asked

Viewed 85 times

2

I’m taking emails from the inbox of an account I created for testing, I’m tracking them with the Node-imap and parse them with the Mailparser and I am able to recover most of the information I need, except the text of the email, because it is in stream format and I do not know how to turn it into a string to send to the client.

I’m already reading the Node.JS documentation to find out how I do it, as I’m also reading the Mailparser documentation, but I still haven’t found exactly what I need, thank you if someone can help me.

1 answer

0


If the Stream return is a buffer you can do something more or less like this:

let string = ''

stream.on('readable',function(buffer){
  let part = buffer.read().toString()
  string += part
  console.log('Stream em string: ' + part)
})

stream.on('end',function(){
 console.log('String final ' + string)
})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.