AS3工作具有任意大的文件 [英] AS3 Working With Arbitrarily Large Files
问题描述
我想读在AS3一个非常大的文件时遇到的问题与运行时只是崩溃在我身上。我目前使用的是的FileStream 的开该文件异步。这并不适用于文件大于300MB左右的工作(崩溃没有一个例外)。
I am trying to read a very large file in AS3 and am having problems with the runtime just crashing on me. I'm currently using a FileStream to open the file asynchronously. This does not work(crashes without an Exception) for files bigger than about 300MB.
_fileStream = new FileStream();
_fileStream.addEventListener(IOErrorEvent.IO_ERROR, loadError);
_fileStream.addEventListener(Event.COMPLETE, loadComplete);
_fileStream.openAsync(myFile, FileMode.READ);
在仰望文档,这听起来像FileStream类仍试图读取整个文件到内存中(这是不好的大文件)
In looking at the documentation, it sounds like the FileStream class still tries to read in the entire file to memory(which is bad for large files).
有没有更适合的类用于读取大文件?我真的想这样的事情只能从将要下一个读取文件加载字节的缓冲FileStream类。
Is there a more suitable class to use for reading large files? I really would like something like a buffered FileStream class that only loads the bytes from the files that are going to be read next.
我期待,我可能需要写,做这对我来说一类,但我需要一次只能读取一张的文件。我假设我可以通过设置的FileStream的位置,并预读属性读一大块出文件中的时间做到这一点。我希望,以节省一些时间,如果有一类这样的已经存在。
I'm expecting that I may need to write a class that does this for me, but then I would need to read only a piece of a file at a time. I'm assuming that I can do this by setting the position and readAhead properties of the FileStream to read a chunk out of a file at a time. I would love to save some time if there is a class like this that already exists.
有没有处理在AS3大型文件的好方法,而无需加载整个内容到内存?
Is there a good way to process large files in AS3, without loading entire contents into memory?
推荐答案
不能创建了一个流,并读取字节块在给定的偏移,一大块的时间......这样:
Can't you create a stream, and read a chunk of bytes at a given offset, a chunk at a time... so:
function readPortionOfFile(starting:int, size:int):ByteArray
{
var bytes:ByteArray ...
var fileStream:FileStream ...
fileStream.open(myFile);
fileStream.readBytes(bytes, starting, size);
fileStream.close();
return bytes;
}
,然后根据需要重复。我不知道这是如何工作的,并没有测试过,但我是在IM pression这个工作的。
and then repeat as required. I don't know how this works, and haven't tested it, but I was under the impression that this works.
这篇关于AS3工作具有任意大的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!