使用 node.js 解析大型 xml 500M [英] parsing large xml 500M with node.js

查看:37
本文介绍了使用 node.js 解析大型 xml 500M的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 isaacs 的 SAX 来解析一个巨大的 xml 文件.还有 La Gentz 推荐.>

进程使用了​​大约 650M 的内存,我该如何减少它或让节点使用更多.

致命错误:CALL_AND_RETRY_0 分配失败 - 进程内存不足

我的 XML 文件大于 300M,它可能会增长到 1GB.

解决方案

您应该将文件流式传输到解析器中,毕竟这是流式解析器的全部意义所在.

var parser = require('sax').createStream(strict, options);fs.createReadStream(file).pipe(parser);

I am using isaacs' SAX to parse a huge xml file. Also recommended by La Gentz.

The process uses about 650M of memory, how can I reduce this or allow node to use even more.

FATAL ERROR: CALL_AND_RETRY_0 Allocation failed - process out of memory

My XML file is larger than 300M it could grow to 1GB.

解决方案

You should stream the file into the parser, that's the whole point of a streaming parser after all.

var parser = require('sax').createStream(strict, options);
fs.createReadStream(file).pipe(parser);

这篇关于使用 node.js 解析大型 xml 500M的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆