From e497de5888124851880b123b2dc154f54ba56667 Mon Sep 17 00:00:00 2001 From: share121 <2854631158@qq.com> Date: Thu, 6 Feb 2025 21:04:58 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.ts | 5 ++++- main_test.ts | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/main.ts b/main.ts index f0eb892..39b335a 100644 --- a/main.ts +++ b/main.ts @@ -29,7 +29,8 @@ export async function download( const mutex = new Mutex(); const { contentLength, filename } = await getURLInfo(); await Deno.mkdir(dirpath, { recursive: true }); - const file = await Deno.open(join(dirpath, filename), { + const filePath = join(dirpath, filename); + const file = await Deno.open(filePath, { write: true, create: true, }); @@ -65,6 +66,8 @@ export async function download( } finally { file.close(); } + + return filePath; } export interface Chunk { diff --git a/main_test.ts b/main_test.ts index 7262909..85fe2e5 100644 --- a/main_test.ts +++ b/main_test.ts @@ -1,5 +1,4 @@ import { crypto } from "jsr:@std/crypto"; -import { join, basename } from "jsr:@std/path"; import { encodeHex } from "jsr:@std/encoding/hex"; import { assertEquals } from "jsr:@std/assert"; import { download } from "./main.ts"; @@ -9,10 +8,9 @@ Deno.test("Download ISO file test", async () => { "https://mirrors.tuna.tsinghua.edu.cn/debian-cd/12.9.0-live/amd64/iso-hybrid/debian-live-12.9.0-amd64-kde.iso"; const dirpath = "."; const threads = 32; - const outputPath = join(dirpath, basename(url)); console.time("Download ISO file test"); - await download(url, outputPath, threads); + const outputPath = await download(url, dirpath, threads); console.timeEnd("Download ISO file test"); console.time("Calculate file hash test");