Convert a stream to string?

2

I'm getting emails from the inbox of an account I created for testing, I'm looking for them with the node-imap and parsing them with MailParser and I'm getting the most of the information I need except the email text, because the same is in stream format and I do not know how to turn it into a string so I can send it to the client.

I am already reading the Node.JS documentation to find out how I do this, as I am also reading the MailParser documentation, but I still do not find exactly what I need, thanks if anyone can help me.

    
asked by anonymous 23.08.2017 / 16:49

1 answer

0

If the Stream return is a buffer you can do something 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)
})
    
28.09.2017 / 18:59