title: Sharp Error: Input buffer contains unsupported image format
body: <p>I want to create image manipulation on the image fetched from the AWS S3 and would like to perform manipulation action on it. I am using stream to solve the problem of loading big files.</p>
  <pre class="lang-js prettyprint-override"><code>import AWS from 'aws-sdk'
  import sharp from 'sharp'
  
  const s3 = new AWS.S3()
  const transformer = (w, res, next) =&gt;
      sharp()
          .resize(w)
          .on('data', (data) =&gt; {
              console.log(data)
              res.write(data, 'binary')
          })
          .on('error', (err) =&gt; next(err))
          .on('end', () =&gt; {
              console.log('finished')
              res.status(200).end()
          })
  
  const readStream = s3
      .getObject({
          Bucket: process.env.UPLOAD_BUCKET_NAME,
          Key: 'test.jpg'
          // Key: `${req.uid.uid}/${req.param('img')}`
      })
      .createReadStream()
  
  const getImage = (w, res, next) =&gt; {
      readStream.pipe(transformer(w, res, next))
      readStream.on('error', (err) =&gt; next(err))
  }
  
  export default getImage
  </code></pre>
  <p>I am calling the getImage method on the route and this function serves images for the first time but when the second time the Image is requested, it throws Error: <strong>Input buffer contains unsupported image format</strong></p>