require('buffer').Buffer
var util = require('util');
var Duplex = require('stream').Duplex;

function transformNodesToGeoJson(options) {
  if (!(this instanceof transformNodesToGeoJson)) {
    return new transformNodesToGeoJson(options)
  }
  Duplex.call(this, options);
  this.readArr = [];
  this.flagToRead = true;
}

util.inherits(transformNodesToGeoJson, Duplex);

transformNodesToGeoJson.prototype._read = function readBytes(n) {
  var self = this;
  while (this.readArr.length) {
    var chunk = this.readArr.shift();
    if (!self.push(chunk)) {
      break;
    }
  }
  if (this.flagToRead) {
    setTimeout(readBytes.bind(self), 1000, n);
  } else {
    self.push(null);
  }
};

transformNodesToGeoJson.prototype._write =
  function (chunk, enc, cb) {
    this.readArr.push(new Buffer(chunk));
    cb();
  };

var transformObject = new transformNodesToGeoJson();

module.exports = transformObject;


@@ -84,16 +84,60 @@
 .Duplex;
+%0Avar osmtogeojson = require('osmtogeojson');
 %0A%0Afuncti
@@ -315,22 +315,21 @@
 %0A  this.
-readAr
+buffe
 r = %5B%5D;%0A
@@ -339,24 +339,23 @@
 his.
-flagToRead = tru
+readFlag = fals
 e;%0A%7D
@@ -477,393 +477,554 @@
 %7B%0A  
-var self = this;%0A  while (this.readArr.length) %7B%0A    var chunk = this.readArr.shift();%0A    if (!self.push(chunk)) %7B%0A      break;%0A    %7D%0A  %7D%0A  if (this.flagToRead) %7B%0A    setTimeout(readBytes.bind(self), 1000, n);%0A  %7D else %7B%0A    self.push(null);%0A  %7D%0A%7D;%0A%0AtransformNodesToGeoJson.prototype._write =%0A  function (chunk, enc, cb) %7B%0A    this.readArr.push(new Buffer(chunk));%0A    cb();%0A  %7D;%0A%0Avar
+console.log('Buffer length: ', this.buffer.length);%0A%7D;%0A%0AtransformNodesToGeoJson.prototype._write = function (chunk, enc, cb) %7B%0A  this.buffer = Buffer.concat(%5Bnew Buffer(this.buffer), new Buffer(chunk)%5D);%0A  if (this.readFlag == true) %7B%0A    this.push(this.buffer);%0A    this.buffer= %5B%5D;%0A  %7D %0A  cb();%0A%7D;%0A%0Avar transformObject = new transformNodesToGeoJson();%0AtransformObject%0A  .on('finish', function () %7B%0A    transformObject.buffer = JSON.stringify(osmtogeojson(JSON.parse(transformObject.buffer.toString())));%0A    transformObject.readFlag = true;%0A   
  tra
@@ -1027,39 +1027,39 @@
  transformObject
- = new 
+.write(
 transformNodesTo
@@ -1051,33 +1051,49 @@
 ransform
-NodesToGeoJson();
+Object.buffer.toString());%0A  %7D);%0A
 %0A%0Amodule
@@ -1119,10 +1119,8 @@
 mObject;
-%0A%0A

Fix transformNodesToGeoJson function