b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

as3 filestream_as3 addeventlistener_appendfilestream

电脑杂谈  发布时间:2016-12-15 13:04:50  来源:网络整理

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).

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.

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

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

as3 addeventlistener_appendfilestream_as3 filestream

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
  }

本文地址:IT屋 » AS3 fileStream appears to read the file into memory

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

appendfilestream_as3 addeventlistener_as3 filestream

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

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

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

 私有函数每个所选的(事件:事件):无效{
        var文件:文件=文件(将event.target);
        跟踪(“每个所选的:名称=”+ file.name);

        VAR流:的FileStream =新的FileStream();

        变种F:文件将event.target =为文件;
        stream.open(F,FileMode.READ); //这里的过程中会锁定,如果你传递文件过大。
        VAR字节:的ByteArray =新的ByteArray();
        stream.readBytes(字节,0,1024);
        迹(字节);
        stream.close();
}
 

非常感谢,提前。

解决方案


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-22900-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...