title: Missing last character while base64 encoding a file from S3 using stream filter
body: <p>I have a very weird issue with PHP's stream conversion filter (<a href="http://php.net/manual/en/filters.convert.php" rel="nofollow">base64_encode</a>). My goal is to read file from s3 bucket using AWS S3 SDK's streamWrapper and base64 encode it, echo it to response. For this I am using following code,</p>
  
  <pre><code>@ob_flush();
  @flush();
  $fh = fopen(&lt;FILE_PATH&gt;, 'r');
  stream_filter_append($fh, 'convert.base64-encode');
  fpassthru($fh);
  fclose($fh);
  </code></pre>
  
  <p>This works for all types of file, but for a text file it drops last character. When we decode the base64 response, last character is missing.</p>
  
  <p>For example,</p>
  
  <p><code>Hello, world!</code> which encodes to <code>SGVsbG8sIHdvcmxkIQ==</code></p>
  
  <p>But the above function omits last character while encoding, producing the following</p>
  
  <p><code>SGVsbG8sIHdvcmxk</code> which decodes to <code>Hello, world</code></p>
  
  <p>Any thoughts guys?</p>
  
  <p>Thank you so much for helping me out.</p>