大佬教程收集整理的这篇文章主要介绍了node.js / v8将大文件读入内存,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
例
我正在尝试在Node.js下使用topojson来转换> 1.1 GB 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
>他们appear to have removed这个内存限制(如果我是正确的,我可能不会)
>这没有成功
版本
> node.js:v0.8.15
> v8:3.11.10.25
fs.readFileSync
来读取整个文件.这样做是打开一个大小的缓冲区(文件的长度),然后填充它.但节点缓冲区
have a maximum size为0x3FFFFFFF字节,或1GB – 1字节.所以你得到了那个例外.
解?打开topojson源并将readFileSync替换为不会将整个文件作为一个块读取的流方法.或者,如果你感觉真的很hackish,可能重新编译具有更大kMaxLength常数的节点…
以上是大佬教程为你收集整理的node.js / v8将大文件读入内存全部内容,希望文章能够帮你解决node.js / v8将大文件读入内存所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。