flash - AS3 fileStream出现将文件读入内存

标签 flash actionscript-3 file-io air

我正在编写一个流程,用户需要选择一个远远超出其可用 RAM 的文件,并将该文件分成小块(用于上传)。

我能够创建对所述文件的文件引用,但是当我尝试将其传递给 fileStream 时,它似乎尝试在对其进行操作之前尝试将其读入内存。

有没有办法让 fileStream 仅获取对文件的引用,然后按照记录的方式使用 readBytes?

这是我的代码...当用户在浏览器对话框中选择文件时调用它。

private function selectHandler(event:Event):void {
        var file:File = File(event.target);
        trace("selectHandler: name=" + file.name );

        var stream:FileStream = new FileStream();

        var f:File = event.target as File;
        stream.open(f, FileMode.READ);  //here the process will lock up if the file you pass it is too large.
        var bytes:ByteArray = new ByteArray();
        stream.readBytes(bytes,0,1024);
        trace(bytes);
        stream.close();
}

非常感谢,提前。

最佳答案

那么,解决方案...

 stream.readAhead = 10000;// some reasonable number
 stream.openAsync(f, FileMode.READ);  //here the process will no longer lock up, if the above chunk is set to a number that Flash can handle.



   //then in your PROGRESS listener you read the bytes into a byteArray
  if(target.availableBytes >= 10000){//you need this because progress gets called many times before the full chunk is read. You only want to use it when you have the full chunk. (you also will want to keep track of the total read and when that total + chunk > fileSize, you'll want to adjust your chunk to read in that last bunch of bytes.
    var bytes:ByteArray = new ByteArray();
    stream.readBytes(bytes,0,event.target.availableBytes); //this will provoke the next segment to get read as well
  }

关于flash - AS3 fileStream出现将文件读入内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4787805/

相关文章:

c - 如果从文件输入中获取,为什么不\n 生成一个新行字符?

flash - 无法在 Flash CS4 中导入 UIComponent?

C++:自定义对象序列化/反序列化失败

html - 使用html禁用嵌入式flash对象的声音

javascript - 使用 Javascript 访问剪贴板 - 没有 Flash?

python - 如何在Python Google App Engine Sdk中配置flex crossdomain.xml

javascript - 防止 iframe 中的恶意 Flash 广告将用户重定向到顶部位置

actionscript-3 - 在读取属性值之前如何测试对象上是否存在属性?

xml - 从对象创建 xml

java - 在文件输入输出java中使用数组列表