0

我有一个应用程序正在下载几个大型二进制文件并将它们保存到磁盘。在某些机器上它工作正常,而在其他一些机器上,每隔一段时间,下载将进行到 99.9% 完成,并且 URLStream 对象不会触发 Event.COMPLETE

这与此处出现的问题几乎相同:

为什么在文件未完成加载时会调度 URLStream 完成事件?

我尝试使用答案之一中描述的“Cache Bust”方法,但仍然没有骰子。

任何帮助,将不胜感激。

这是一些示例代码,可帮助说明我正在尝试做的事情:

var contentURL:String = "http://some-large-binary-file-in-amazon-s3.tar";

var stream:URLStream = new URLStream();
stream.addEventListener(Event.COMPLETE, function(e:Event):void{
    //This should fire when the file is done downloading
    //On some systems this fails to fire once in a while
    //On other systems it never fails to fire               
});
stream.addEventListener(ProgressEvent.PROGRESS, function(pe:ProgressEvent):void{
    //Write the bytes available in the stream and save them to disk
   //Note that a download will reach 100% complete in terms of total progress but the 'complete' event might still not fire.
});

var urlRequest:URLRequest = new URLRequest(contentURL);
//Here we might add some headers to the URL Request for resuming a file
//but they don't matter, the 'Event.COMPLETE' will fail to fire with our without
//these headers
addCustomHeaders( urlRequest );

stream.load( urlRequest );
4

1 回答 1

0

Imo 这是一个意味着失败的代码,你故意放弃对正在发生的任何事情的任何控制,只是假设一切都会自行工作并顺利进行。我从来没有遇到过 URLStream 类的任何问题,但这基本上是我从未做过的事情:

  1. 我从不注册所有可用的不同错误事件(您没有注册任何)。

  2. 我从不使用匿名听众。尽管在下载完成之前它们不应该是 GC,但这在 imo 中是一个不必要的不​​安全赌注,特别是因为 URLStream 在加载最后一位时空闲一点的情况并不少见。如果删除这些匿名听众真的能解决问题,我不会感到惊讶。

于 2016-04-15T13:50:32.823 回答