title: createReadStream multiple times on the same fd
body: <p><a href="https://stackoverflow.com/questions/13932967">In a previous question</a> it seemed that the only way to do random-access reads from a file in node.js is to use <a href="http://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options" rel="nofollow noreferrer"><code>fs.createReadStream()</code></a> with its optional <code>fd</code>, <code>start</code>, and <code>end</code> fields.</p>
  
  <p>This worked fine in my simplest tests. But in my project I need to repeatedly read from different offsets of a binary file. This failed in a strange way so I came up with a minimal test case:</p>
  
  <pre><code>var fs = require('fs');
  
  fs.open('test.txt', 'r', function (err, fd) {
    if (err) {
      console.error('error opening file: ' + err);
    } else {
      fs.createReadStream(null, {fd: fd, start: 2, end: 5}).on('error', function (err) {
          throw e;
        }).on('close', function () {
          console.log('outer close');
        }).on('data', function (data) {
          console.log('outer data', data);
        }).on('end', function () {
          console.log('outer end');
  
          fs.createReadStream(null, {fd: fd, start: 0, end: 3}).on('error', function (err) {
              throw e;
            }).on('close', function () {
              console.log('inner close');
            }).on('data', function (data) {
              console.log('inner data', data);
            }).on('end', function () {
              console.log('inner end');
  
              // more code to execute after both reads
            });
        });
    }
  });
  </code></pre>
  
  <p>The inner <code>end</code> event is never received. (The outer <code>close</code> is received inconsistently, but I don't need to attach code to it.)</p>
  
  <p>I've implemented this project before in Perl and even in JavaScript as a Firefox extension, but it's proving difficult under node. This is also a test for whether I can start <a href="https://stackoverflow.com/questions/13899623">using node.js as a general purpose scripting language</a>.</p>