是否可以在FileStream中设置缓冲区大小?

时间:2011-08-18 06:47:19

标签: actionscript-3 flex4

我需要将大数据写入磁盘,因此我使用FileStream.openAsync()

this.file_stream = new FileStream();
this.file_stream.openAsync(fl, FileMode.WRITE);

//Write large get from database
while(i < 10240000) {
    this.file_stream.write(bigDatas)
    i = i + 1;
}

然后,该应用程序被Linux kenkel杀死(来自'dmesg'的消息副本):

  

被杀的进程4267(MyFlex)total-vm:1282708kB,anon-rss:863176kB,file-rss:756kB

那么,有没有办法在FileStream中设置缓冲区大小?

1 个答案:

答案 0 :(得分:0)

您正在尝试执行一次数百万次的循环。

问题不在于FileStream的缓冲区。感谢Linux停止执行您的应用程序并避免系统爆炸。

您需要保存一个文件,保存文件后,转到下一个,查看代码,“writeFile”函数等待CLOSE事件再次执行。

import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.events.Event;

var file:File;
var stream:FileStream = new FileStream();

stream.addEventListener(Event.CLOSE, writeFile);

var cont:uint = 0;
//---I do not think that you need to run a code 10 million times (This code will save the file 10 times)
var total:uint = 10;

//---Write file in the Desktop in the folder "test"
function writeFile(evt:Event = null){

    cont++;

    if(cont == total + 1) {

        stream.removeEventListener(Event.COMPLETE, writeFile);

        trace("finish");

    }else{

        trace("write file number " + cont);

        file = File.desktopDirectory.resolvePath("test/data" + cont);

        stream.openAsync(file, FileMode.WRITE);

        stream.writeByte(0xFF);

        stream.close();

    }

}

//---Execute the function for first time
writeFile();