AS3 FILESTREAM出现读取文件到内存 [英] AS3 fileStream appears to read the file into memory

查看:1035
本文介绍了AS3 FILESTREAM出现读取文件到内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编写过程中,用户需要选择,远远超出他们的availble的RAM文件,并具有分解成小块(上传)该文件。

I am writing a process where users will need to select a file that far exceeds their availble RAM and have that file broken up into small chunks (for upload).

我能够创建一个文件引用说文件,但是当我试着将它传递给FILESTREAM,它似乎试图行事前读的东西到内存中。

I'm able to create a File reference to said file, but when I try to pass it to the fileStream, it appears to try to read the thing into memory before acting on it.

有没有办法让FILESTREAM只取了参考文件,然后利用的ReadBytes它的记录方式?

Is there a way to get fileStream to just take the reference to the file and then utilize readBytes the way it's documented?

下面是我的code ...当用户选择浏览器对话的文件,它被称为。

Here is my code... it's called when the user selects the File in the browser dialogue.

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

非常感谢,提前。

Much obliged, in advance.

推荐答案

因此​​,该解决方案...

So, the solution...

 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
  }

这篇关于AS3 FILESTREAM出现读取文件到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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