Adobe AIR。获取文件的MD5

发布于 01-06 20:43 字数 847 浏览 2 评论 0原文

我已经这样做了,但 Adob​​e Air 挂起几秒钟。

        private function test():void
        {
            fileStream = new FileStream(); 
            fileStream.addEventListener(IOErrorEvent.IO_ERROR, fileError);
            fileStream.addEventListener(Event.COMPLETE, opened);
            fileStream.openAsync(filePath, FileMode.READ);
        }

        protected function opened(event:Event):void
        {
            var bytes:ByteArray = new ByteArray();
            fileStream.readBytes(bytes);
            fileStream.close();
            // MD5Stream from package com.adobe.crypto.MD5Stream  https://github.com/mikechambers/as3corelib/blob/master/src/com/adobe/crypto/MD5Stream.as
            var md5stream:MD5Stream = new MD5Stream;
            trace(md5stream.complete(bytes)); // md5    
        }

如何让获取md5的过程不挂起?

I've done it this way, but Adobe Air hangs for several seconds.

        private function test():void
        {
            fileStream = new FileStream(); 
            fileStream.addEventListener(IOErrorEvent.IO_ERROR, fileError);
            fileStream.addEventListener(Event.COMPLETE, opened);
            fileStream.openAsync(filePath, FileMode.READ);
        }

        protected function opened(event:Event):void
        {
            var bytes:ByteArray = new ByteArray();
            fileStream.readBytes(bytes);
            fileStream.close();
            // MD5Stream from package com.adobe.crypto.MD5Stream  https://github.com/mikechambers/as3corelib/blob/master/src/com/adobe/crypto/MD5Stream.as
            var md5stream:MD5Stream = new MD5Stream;
            trace(md5stream.complete(bytes)); // md5    
        }

How to make the process of getting md5 without hanging?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若相惜即相离2025-01-13 20:43:23

尝试使用Bloody 的 MD5 实现。显然快了很多

虽然它会加速哈希计算,甚至可能充分加速,但您并没有真正解决根本问题,即您希望在单线程应用程序模型中实现非阻塞操作。在 Flash/AIR 中,这通常是通过将工作分解为更小的块来完成的,并且只处理每个帧的一个块,而不是在一个帧中一次性处理所有任务。甚至还有一个很酷的框架 简化这个!

我注意到您当前使用的库 MD5Stream 是为增量更新而构建的 - 因此您可以轻松地每帧向其提供文件的小块,直到处理整个文件。这将使帧速率在计算哈希时保持相对恒定。

Try using Bloody's MD5 implementation. It's apparently a lot faster.

While it will speed up the hash calculation, perhaps even adequately, you're not really solving the underlying problem, which is that you want a non-blocking operation in a single threaded application model. In Flash/AIR, this is generally done by breaking the work up into smaller chunks, and doing only one chunk's worth of processing each frame, instead of all at once during one frame. There's even a cool framework to simplify this!

I noticed that the library you're currently using, MD5Stream, is built for incremental updates -- so you can easily feed it little chunks of the file each frame until the entire file is processed. This will allow the frame rate to stay relatively constant while the hash is computed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文