JavaScript中解析文件中大量数据的最有效方法是什么 [英] What is the most efficient way in JavaScript to parse huge amounts of data from a file

查看:87
本文介绍了JavaScript中解析文件中大量数据的最有效方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript从文件中解析大量数据的最有效方法是什么?

What is the most efficient way in JavaScript to parse huge amounts of data from a file?

目前我使用JSON解析来序列化未压缩的250MB文件,这是真慢是否有一种简单而快速的方法可以从文件中读取JavaScript中的大量数据而无需遍历每个字符?存储在文件中的数据只是几个浮点数组?

Currently I use JSON parse to serialize an uncompressed 250MB file, which is really slow. Is there a simple and fast way to read a lot of data in JavaScript from a file without looping through every character? The data stored in the file are only a few floating point arrays?

UPDATE:
该文件包含一个3d网格,6个缓冲区(vert,uv等)。缓冲区也需要表示为类型化数组。流不是一个选项,因为在图形引擎可以继续之前必须完全加载文件。也许更好的问题是如何以最有效的方式将大型类型的数组从文件传输到javascript。

UPDATE: The file contains a 3d mesh, 6 buffers (vert, uv etc). Also the buffers need to be presented as typed arrays. streaming is not a option because the file has to be fully loaded before the graphics engine can continue. Maybe a better question is how to transfer huge typed arrays from a file to javascript in the most efficient way.

推荐答案

我会推荐这种JavaScript或流解析器的基于SAX的解析器。

I would recommend a SAX based parser for these kind of JavaScript or a stream parser.

DOM解析会将整个内容加载到内存中,这不是大文件的方法就像你提到的那样。

DOM parsing would load the whole thing in memory and this is not the way to go by for large files like you mentioned.

对于基于Javascript的SAX解析(XML格式)你可以参考
< a href =https://code.google.com/p/jssaxparser/\"rel =nofollow> https://code.google.com/p/jssaxparser/

对于JSON 您可以编写自己的,以下链接演示如何在Javascript
中编写一个基于SAX的基本解析器 http://ajaxian.com/ archives / javascript-sax-based-parser

for JSON you might write your own, the following link demonstrates how to write a basic SAX based parser in Javascript http://ajaxian.com/archives/javascript-sax-based-parser

这篇关于JavaScript中解析文件中大量数据的最有效方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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