节点中的Buffer.js错误 - JSON太大

时间:2017-02-11 21:03:12

标签: javascript node.js

我收到此错误

buffer.js:495
        throw new Error('"toString()" failed');

我正在尝试使用此功能一次解析大量数据:

exports.markers = function(resp, resp2) {

  this.markersOne = function() {
    var lat, lng = [];
    return resp.map(function(element) {
      lat = element.location_1.coordinates[1];
      lng = element.location_1.coordinates[0];
      return new google.maps.LatLng(lat, lng);
    })
  }

  this.markersTwo = function() {
    return resp2.map(function(element) {
      var lat, lng = [];
      if (element.location_1 != undefined && element.location_1.length > 0) {
        lat = element.location_1.slice(1, -12);
        lng = element.location_1.slice(10, -1);
        return new google.maps.LatLng(lat, lng);
      }
    })
  }

  var result = this.markersOne().concat( this.markersTwo() );
  console.log(result);
  return result;

  }

我有两个数据库作为JSON文件下载到目录中。

一个是304 MB,另一个是80 MB。

看到304 MB是如何过大的,我可以通过其他方式解决这个问题?

1 个答案:

答案 0 :(得分:0)

将我的评论移至答案:

结帐stackoverflow post。好像你必须用读取流读取文件而不是只需要文件。

您可以尝试使用此库:http://www.github.com/dominictarr/JSONStream