title: Nodeschool's Stream-Adventure #12 Duplexer redux
body: <p>It's been days since I'm trying several ways to solve this exercice. I give up. What am I doing wrong here ? Why am I getting "write after end" error if the event I'm using is the "end" event and I don't write anything to the pipe ? I'm just changing an object after it's use. Or at least I think so.</p>
  
  <pre><code>var duplexer2 = require("duplexer2");
  var through = require('through2');
  
  
  module.exports = function (counter) {
      var countries = {};        
  
      var duplex = duplexer2(through.obj(function (obj, encoding, done) {
          if (obj.country in countries)
              countries[obj.country]++;
          else 
              countries[obj.country] = 1;  
          done();
      }), counter);
  
      duplex.on("finish", function() {
          counter.setCounts(countries);
      });
  
      counter.pipe(duplex);
  
      return duplex;
  };
  </code></pre>
  
  <p>If I substitute the line <code>counter.setCounts(countries);</code> for <code>console.log(countries)</code> I see that it's populated correctly.</p>
  
  <p>Problem text: <a href="http://pastebin.com/vAM4vKZg" rel="nofollow">http://pastebin.com/vAM4vKZg</a></p>
  
  <p>I have read this exercice test file and counldn't get any clue from it as it only compares the objects to see if they're correct.</p>