title: Changing a buffer from a ReadStream into an actual file
body: <p>So I have this code:</p>
  
  <pre><code>downloadFile(file_id) {
      return new Promise((resolve, reject) =&gt; {
          var mongoose = require('mongoose');
          var Grid = require('gridfs-stream');
          var fs = require('fs');
  
          mongoose.connect(config.db, {useNewUrlParser: true},).catch(e =&gt; console.log(e));
          var conn = mongoose.connection;
          Grid.mongo = mongoose.mongo;
          var gfs = Grid(conn.db);
          console.log('downloadfile', file_id);
          var read_stream = gfs.createReadStream({_id: file_id});
          let file = [];
          read_stream.on('data', function (chunk) {
              file.push(chunk);
          });
          read_stream.on('error', e =&gt; {
              console.log(e);
              reject(e);
          });
          return read_stream.on('end', function () {
              resolve(file);
          });
      });
  }
  </code></pre>
  
  <p>And I'm calling it like this:</p>
  
  <pre><code>Account.findById(req.params._id)
      .then(async account =&gt; {
          const file = await functions.downloadFile(account.employer.logo);
          res.render('users/employer/booth', {
              title: 'Employer Booth',
              user: req.user,
              postings: postings,
              employer: account.employer,
              event: event,
              logo: logo,
          });
      });
  </code></pre>
  
  <p>How can I either save this file to the server and serve it as an image, or just send it to the view and show it in an <code>&lt;img&gt;</code> tag? </p>
  
  <p>I tried doing something like this:</p>
  
  <pre><code>read_stream.on('open', function () {
      var imgFile = fs.createWriteStream(`/public/images/logos/${file_id}.jpg`);
      var write_stream = read_stream.pipe(imgFile);
      read_stream.pipe(res);
  });
  read_stream.on('error', e =&gt; {
      console.log(e);
  });
  </code></pre>
  
  <p>But this wasn't able to read the saved file, and the file wasn't saved anywhere.</p>