title: Errno::EINVAL Invalid argument @ io_fread
body: <p>I'm attempting to download a ~2GB file and write it to a file locally but I'm running into this issue:</p>
  
  <p><a href="https://i.stack.imgur.com/jXf9g.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jXf9g.png" alt="enter image description here"></a></p>
  
  <p>Here's the applicable code:</p>
  
  <pre><code>  File.open(local_file, "wb") do |tempfile|
      puts "Downloading the backup..."
  
      pbar = nil
      open(backup_url,
           :read_timeout =&gt; nil,
           :content_length_proc =&gt; lambda do |content_length|
             if content_length&amp;.positive?
               pbar = ProgressBar.create(:total =&gt; content_length)
             end
           end,
           :progress_proc =&gt; -&gt;(size) { pbar&amp;.progress = size }) do |retrieved|
            begin
              tempfile.binmode
              tempfile &lt;&lt; retrieved.read
              tempfile.close
            rescue Exception =&gt; e
              binding.pry
            end
      end
  </code></pre>