AS3 处理任意大文件

编程入门 行业动态 更新时间:2024-10-15 22:26:46
本文介绍了AS3 处理任意大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我试图在 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 的 position 和 readAhead 属性来一次从文件中读取一个块来做到这一点.如果已经存在这样的类,我很想节省一些时间.

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;
}

然后根据需要重复.我不知道这是如何工作的,也没有测试过,但我的印象是它有效.

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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-19 19:46:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/968460.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!