title: Using Sharp & Express causes exception : "Input buffer contains unsupported image format"
body: <p>I'm using Node &amp; Express &amp; Sharp to:</p>
  
  <blockquote>
    <p>Download an image as stream -> convert to webp -> response the user
    with the converted image</p>
  </blockquote>
  
  <p>This code does the job : </p>
  
  <pre><code>import express   from 'express';
  import * as url  from 'url';
  const sharp = require('sharp');
  var request = require('request');
  
  app.get('*', function (req, res1)
  {
      let imgPath = url.resolve('http://localhost', req.originalUrl);
  
      request({
                  url     : imgPath,
                  encoding: null
              }, function (err, res, bodyBuffer)
              {
                  sharp(bodyBuffer)
                      .webp({quality: 90})
                      .toBuffer()
                      .then((myBuffer) =&gt;
                            {
                                res1.writeHead(200, {'Content-Type': 'image/webp'});
                                res1.end(myBuffer, 'binary');
                            }).catch(error=&gt;console.log(error));;
              });
  
  });
  
  app.listen(app.get('port'), function ()
  {
      console.log('app running on port', app.get('port'));
  });
  </code></pre>
  
  <p>I must say that code <em>does work</em> (an image as webp is served) , but I do get an exception after image is served : </p>
  
  <blockquote>
  <pre><code>app running on port 5000
  [Error: Input buffer contains unsupported image format]
  </code></pre>
  </blockquote>
  
  <p><strong>Question:</strong></p>
  
  <p>Why do I get this error and how can I solve it ?</p>
  
  <p>NB<br>
  <a href="https://gist.github.com/RoyiNamir/c7c8e904eae3dacd848a6e3928729b32#file-imageresizer-ts-L35" rel="nofollow noreferrer">I've also tried</a> the solution suggested <a href="https://github.com/lovell/sharp/issues/1190#issuecomment-381311773" rel="nofollow noreferrer">here</a>, Without success :
     <code>Cannot pipe, not readable</code></p>