问题
如何在node.js下将大于1.1GB的文件读入内存?
示例
我正在尝试在node.js下使用topojson将大于1.1GB的GeoJSON文件转换为TopoJSON格式。
$ topojson -o outfile.json larger_than_one_point_one_GB_input_file.json
(以上方法适用于不超过517 MB的文件)
导致以下错误
buffer.js:242
this.parent = new SlowBuffer(this.length);
^
RangeError: length > kMaxLength
at new Buffer (buffer.js:242:21)
at Object.fs.readFileSync (fs.js:200:14)
at /usr/local/share/npm/lib/node_modules/topojson/bin/topojson:61:26
at Array.forEach (native)
at Object.<anonymous> (/usr/local/share/npm/lib/node_modules/topojson/bin/topojson:60:8)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
我尝试过的
- 广泛搜索
- 命令行内存设置
--max-stack-size=2147000000
--max_executable_size=2000
--max_new_space_size=2097152
--max_old_space_size=2097152
- 编译最新的v8版本到自定义node.js安装中
- 他们似乎已经移除了这个内存限制(如果我正确的话,我可能不正确)
- 这没有成功
版本
- node.js:v0.8.15
- v8:3.11.10.25
readFileSync
。如果成功了,我很乐意将您的答案标记为正确答案。谢谢! - JeffJSON.stringify
调用 - 这也可能会出现相同的错误。 - configuratorkMaxLength
常量。从我的粗略扫描中,看起来其他所有内容都应该“只是工作”。 - configurator