如何从文件流在Adobe AIR的ByteArray?文件、Adobe、ByteArray、AIR

2023-09-09 21:27:29 作者:安于沫

我读的限制(小 - 15 - 500 MB的文件)。 我需要能够把所有文件的字节到一个单一的字节组。 所以我有一个函数:

I read limited (small - 15 - 500 mb files). I need to be able to put all file bytes into one single bytearray. So I have a function:

        [Bindable]
        public var ba:ByteArray = new ByteArray;
        //.... code ....//
        protected function fileOpenSelected(event:Event):void
        {
            currentFile = event.target as File;
            stream = new FileStream();
            stream.openAsync(currentFile, FileMode.READ);
            stream.readBytes(ba);
            stream.close();

                            MyFunction(ba);
        }

但它不工作=( - 给我的错误:错误#2030:文件结尾遇到

But it does not work=( - gives me Error: Error #2030: End of file was encountered.

如何从流获取完整的字节组使用它作为普通的ByteArray?

How to get a full bytearray from stream to use it as normal bytearray?

推荐答案

不点一的FileStream ,你没有一个正常的的ByteArray ,但异步读?它实现 的IDataInput ,让您可以从它只要方bytesAvailable 是更大的阅读比0。

isn't the point of a FileStream that you don't have a normal ByteArray, but read asynchronously? It implements IDataInput, allowing you to read from it as long as bytesAvailable is bigger than 0.

这是每一个进步事件,你只需的ReadBytes 到输出的ByteArray ,一旦你得到一个完整的事件,你可以使用它。

on every progress event, you can just readBytes into an output ByteArray and once you get a complete event, you can use it.

格尔茨 back2dos

greetz back2dos