title: javascript save file from (sinatra's) streaming response
body: <p>I'm using <a href="https://github.com/sinatra/sinatra#streaming-responses" rel="nofollow">streaming response</a> on server side - running sinatra.</p>
  
  <p>How can I handle the client side file download (javascript + angular) in a way, that my streaming response would not get fully loaded first and offered only afterwards to be saved to file?</p>
  
  <p>My current impl. looks similar to this one (using <a href="https://github.com/eligrey/FileSaver.js" rel="nofollow">FileSaver</a>):</p>
  
  <pre><code>$http.post('/foo', bar)
          .success(function (data) {
              var blob = new Blob([data], {type: "text/plain;charset=utf-8"});
              saveAs(blob, 'A.csv');
          }).
  </code></pre>
  
  <p>Still I feel like response gets downloaded completely first and only afterwards offered for save.</p>
  
  <p>The thing is, that file downloaded can be huge, so just wanted to provide fast response to end user.</p>