title: Abort ReadStream on client connection close
body: <p>I am trying to send a (huge) file with a limited amount of data passing every second (using <kbd><strong><a href="https://github.com/TooTallNate/node-throttle" rel="nofollow">TooTallNate/node-throttle</a></strong></kbd>):</p>
  
  <pre><code>var fs = require('fs');
  var Throttle = require('throttle');
  var throttle = new Throttle(64);
  
  throttle.on('data', function(data){
      console.log('send', data.length);
      res.write(data);
  });
  
  throttle.on('end', function() {
      console.log('error',arguments);
      res.end();
  });
  
  var stream = fs.createReadStream(filePath).pipe(throttle);
  </code></pre>
  
  <p>If I cancel the download at the clients browser, the stream will just continue until it completly transferred.<br>
  I also tested the scenario above with <kbd><strong><a href="https://github.com/tec27/node-throttled-stream" rel="nofollow">npm node-throttled-stream</a></strong></kbd>, same behavour.</p>
  
  <p><strong>How to cancel the stream if the browser closed his request?</strong></p>
  
  <hr>
  
  <h2>Edit:</h2>
  
  <p>I am able to obtain the connections <code>close</code> event by using</p>
  
  <pre><code>req.connection.on('close',function(){});
  </code></pre>
  
  <p>But the <code>stream</code> has neither a <code>destroy</code> nor an <code>end</code> or <code>stop</code> property which I could use to stop the <code>stream</code> from further reading.</p>
  
  <p>I does provide the property <code>pause</code> <kbd><strong><a href="http://nodejs.org/api/stream.html#stream_readable_pause" rel="nofollow">Doc</a></strong></kbd>, but I would rather stop node from reading the whole file than just stopping to recieve the contents (as described in the doc).</p>