title: Error: stream.push() after EOF
body: <p>Playing with node steams</p>
  
  <p>This code reads from index.js and writes to indexCopy.js - kind of file copy.
  Target file got created, but during execution exception is thrown:</p>
  
  <pre><code>node index.js
  events.js:183
        throw er; // Unhandled 'error' event
        ^
  
  Error: stream.push() after EOF
      at readableAddChunk (_stream_readable.js:240:30)
      at MyStream.Readable.push (_stream_readable.js:208:10)
      at ReadStream.f.on (C:\Node\index.js:16:28)
      at emitOne (events.js:116:13)
      at ReadStream.emit (events.js:211:7)
      at addChunk (_stream_readable.js:263:12)
      at readableAddChunk (_stream_readable.js:250:11)
      at ReadStream.Readable.push (_stream_readable.js:208:10)
      at fs.read (fs.js:2042:12)
      at FSReqWrap.wrapper [as oncomplete] (fs.js:658:17)
  
  C:\Node&gt;
  </code></pre>
  
  <p>This is code:</p>
  
  <pre><code>var util = require('util');
  var stream = require('stream');
  var fs = require('fs');
  
  
  var MyStream = function(){
      stream.Readable.call(this)
  }
  
  util.inherits(MyStream,stream.Readable);
  
  
  MyStream.prototype._read = function(d){
  
      f = fs.createReadStream("index.js");
      f.on('data',(d)=&gt;{this.push(d)});
      f.on('end',()=&gt;{this.push(null)}); //when file finished need to close stream
  
  }
  
  
  var f = fs.createWriteStream("indexCopy.js")
  
  var myStream = new MyStream()
  myStream.pipe(f);
  </code></pre>
  
  <p>I tried to call this.push(null) in 'data' event, in that case even target file is not created and code fails with the exception.</p>
  
  <p>I realize that copy file should be done easier with pipe() function - I am just experimenting/learning.
  What is wrong with my approach?</p>