- $context = stream_context_create([],["notification" => function($notification, $severity, $message, $code, $bytes_cur, $bytes_max) {
- switch ($notification) {
- case STREAM_NOTIFY_CONNECT:
- $this->debug("\n");
- break;
- case STREAM_NOTIFY_PROGRESS:
- if ($bytes_max) {
- $bytes_pct = $bytes_cur/$bytes_max;
- $this->debug("\r %3d%% [%s>%s] ",
- $bytes_pct*100,
- str_repeat("=", round(70*$bytes_pct)),
- str_repeat(" ", round(70*(1-$bytes_pct)))
- );
- }
- break;
- case STREAM_NOTIFY_COMPLETED:
- /* this is not generated, why? */
- break;
- }
- }]);
- if (!$remote = fopen($source, "r", false, $context)) {
- $this->error(null);
- exit(2);
- }
- $local = new Tempfile("remote");
- if (!stream_copy_to_stream($remote, $local->getStream())) {
- $this->error(null);
- exit(2);
- }
- $local->closeStream();
- $this->info("OK\n");
+ $task = new Task\StreamFetch($source, function($bytes_pct) {
+ $this->debug(" %3d%% [%s>%s] \r",
+ floor($bytes_pct*100),
+ str_repeat("=", round(50*$bytes_pct)),
+ str_repeat(" ", round(50*(1-$bytes_pct)))
+ );
+ });