var constants = require('./constants');
var readBuffer = require('./readBuffer');
var eof = require('./readBuffer');

module.exports = function(buffer, startOffset, howMany) {
  var ta_struct = {
    buffer: buffer,
    cursor: startOffset === undefined ? 0 : startOffset,
    bufferLength: buffer.byteLength,
    refpoint: new Int32Array(4 /* max dims */)
  };
    
  var features = [];
  
  while (ta_struct.cursor < ta_struct.bufferLength) {
    readBuffer(ta_struct);
    var geometry = {};
    switch(ta_struct.type) {
      case constants.POINT:
        geometry.type = "Point"
        geometry.coordinates = toCoords(ta_struct.res, ta_struct.ndims)[0];
        break;
      case constants.LINESTRING:
        geometry.type = "LineString"
        geometry.coordinates = toCoords(ta_struct.res, ta_struct.ndims);
        break;
      case constants.POLYGON:
        geometry.type = "Polygon"
        var c = ta_struct.res;
        geometry.coordinates = [];
        c.forEach(function(c) {
          geometry.coordinates.push(toCoords(c, ta_struct.ndims));
        })
        break;
    }
    features.push({ type: "Feature", geometry: geometry });
  }
  
  return {
    type: 'FeatureCollection',
    features: features
  };
}


var toCoords = function(coordinates, ndims) {
    var coords = []
    for (var i = 0, len = coordinates.length; i < len; i += ndims) {
      var pos = []
      for (var c = 0; c < ndims; ++c) {
        pos.push(coordinates[i + c])
      }
      coords.push(pos);
    }
    return coords;
  }

@@ -1274,18 +1274,16 @@
 dims) %7B%0A
-  
   var co
@@ -1292,18 +1292,16 @@
 ds = %5B%5D%0A
-  
   for (v
@@ -1359,26 +1359,24 @@
 dims) %7B%0A    
- 
- 
 var pos = %5B%5D
@@ -1376,18 +1376,16 @@
 os = %5B%5D%0A
-  
     for 
@@ -1410,26 +1410,24 @@
 ims; ++c) %7B%0A
-  
       pos.pu
@@ -1453,22 +1453,18 @@
 c%5D)%0A    
-  %7D%0A  
+%7D%0A
     coor
@@ -1479,22 +1479,18 @@
 pos);%0A  
- 
- 
 %7D%0A
-  
   return
@@ -1498,12 +1498,10 @@
 coords;%0A
-  
 %7D%0A

Fix indent