AS3 Working With Arbitrarily Large Files

你。 提交于 2019-12-03 17:07:42

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.

FlashDictionary

You can use the fileStream.readAhead and fileStream.position properties to set how much of the file data you want read, and where in the file you want it to be read from.

Lets say you only want to read megabyte 152 of a gigabyte file. Do this; (A gigabyte file consists of 1073741824 bytes) (Megabyte 152 starts at 158334976 bytes)

var _fileStream = new FileStream();
_fileStream.addEventListener(Event.COMPLETE, loadComplete);
_fileStream.addEventListener(ProgressEvent.PROGRESS, onBytesRead);
_fileStream.readAead = (1024 * 1024); // Read only 1 megabyte  
_fileStream.openAsync(myFile, FileMode.READ);
_fileStream.position = 158334976; // Read at this position in file  

var megabyte152:ByteArray = new ByteArray();

function onBytesRead(e:ProgressEvent)
{
    e.currentTarget.readBytes(megabyte152);
    if (megabyte152.length == (1024 * 1024))
    {
        chunkReady();
    }
}

function chunkReady()
{
    // 1 megabyte has been read successfully \\  
    // No more data from the hard drive file will be read unless _fileStream.position changes \\  
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!