const fs = require("fs"); const { pipeline } = require('node:stream/promises'); async function wUpload(client , from, to){ const totalSize = fs.statSync(from).size; const rs = fs.createReadStream( from ); let wSize = 0; let rSize = 0; rs.on("data", (r)=>{ rSize += r.length; console.log("r", rSize * 100 / totalSize) }) const ws = client.createWriteStream(to) ws.on("data", (r)=>{ wSize += r.length; console.log("w", wSize * 100 / totalSize) }) ws.on("finish", ()=>{ console.log("finish") }) return pipeline( rs, ws ); } async function main(){ const webdav = await import("webdav"); const client = webdav.createClient( "http://baishe.fullstack.club:5244/dav", { username: "cheney", password: "722V587" } ); // const client = webdav.createClient( // "http://172.16.17.230:5244/dav", // { // username: "kit", // password: "kitkit" // } // ); // Get directory contents const directoryItems = await client.getDirectoryContents("/"); console.log(directoryItems) // await pipeline( // client.createReadStream( // "/index.json" // ), // fs.createWriteStream("./xxx.json") // ); // let rs = fs.createReadStream("D:\\fullstack\\TDevOps\\kit\\dist\\windows\\kit.exe") // rs.on("data", (r)=>{ // console.log("r", r.length) // }) // let stat = await client.stat("/kitw.exe"); // console.log("stat", stat) // let ws = client.createWriteStream( // "/kit.exe" // ); // ws.on("data", (r)=>{ // console.log("w", r.length) // }) // await pipeline(rs , ws ); // console.log("end") await wUpload( client, "./kit", "/kit" ) // await wUpload( client, "../dist/windows/kit.exe", "/modules/kit/0.1.20240227094429/Windows/X86_64/kit.exe" ) console.log("over") } main()