diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php new file mode 100644 index 0000000..a7731fd --- /dev/null +++ b/app/Console/Commands/Test.php @@ -0,0 +1,132 @@ + 1024 * 1024 * 1024) { + // $append_size = 1024 * 1024 * 1024; + // } elseif ($total_size > 1024 * 1024) { + // $append_size = 1024 * 1024; + // } + + // 将 append_size 转换为 MB + $append_size_mb = $append_size / 1024 / 1024; + + echo 'append size: '.$append_size_mb.' MB'.PHP_EOL; + + // 重置 + curl_setopt($ch, CURLOPT_NOBODY, 0); + + // 创建一个空文件 + $storage->put('download.bin', ''); + + do { + if (! $support) { + // 设置下载范围 + curl_setopt($ch, CURLOPT_RANGE, "$start-$end"); + $data = curl_exec($ch); + $current_size = curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD); + + // file_put_contents('download.bin', $data, FILE_APPEND); + $storage->append('download.bin', $data, null); + + // $bukkit_name = config('filesystems.disks.cos.bucket') . '-' . config('filesystems.disks.cos.app_id'); + // cos via app + // dd(app('cos')); + // $result = app('cos')->appendObject([ + // 'Bucket' => $bukkit_name, + // 'Key' => 'download.bin', + // 'Position' => $start, //追加对象位置 + // 'Body' => $data, //读取文件内容 + // ]); + + $downloaded_size += $current_size; + $start = $end + 1; + $end += $append_size; + + // 判断是否下载完毕 + if ($downloaded_size >= $total_size) { + break; + + echo 'download complete'; + } + + // download progress + echo 'downloaded: '.$downloaded_size.' of '.$total_size.' bytes'.PHP_EOL; + } else { + echo 'server not support range download'.PHP_EOL; + exit; + + // stream download + $fp = fopen('download.bin', 'w'); + curl_setopt($ch, CURLOPT_FILE, $fp); + $data = curl_exec($ch); + + fclose($fp); + + echo 'download complete without range'; + + break; + } + } while ($current_size < $total_size); + + curl_close($ch); + + return CommandAlias::SUCCESS; + } +} diff --git a/composer.lock b/composer.lock index 2721c5d..e17ac70 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "74897af5615b8e629deee52fb4f7bba4", + "content-hash": "19a1f14b2bbf08e0615ed948d4f6ddd2", "packages": [ { "name": "aws/aws-crt-php", @@ -12965,7 +12965,8 @@ "ext-pcntl": "*", "ext-pdo": "*", "ext-posix": "*", - "ext-zip": "^1.19" + "ext-zip": "^1.19", + "ext-redis": "*" }, "platform-dev": [], "plugin-api-version": "2.3.0"