gpt4 book ai didi

javascript - 为什么我完成的种子(有时)没有写入磁盘?

转载 作者:行者123 更新时间:2023-11-30 19:01:22 24 4
gpt4 key购买 nike

我尝试用 electron 和 webtorrent 写一个小的 torrent 客户端。一开始一切似乎都很好,但有时当 torrent 下载完成时,生成的文件没有写入磁盘。

我的项目是通过 SimulatedGREG/electron-vue 样板设置的。

这是我的 torrent 客户端类的代码:

const WebTorrent = require('webtorrent');
const client = new WebTorrent();
export default class TorrentClient {
download (downloadInfo) {
console.log('download torrent from magnet link:', downloadInfo.magnetLink);

let torrent = client.add(downloadInfo.infoHash);
torrent.on('download', function (bytes) {
console.log('just downloaded: ' + bytes);
console.log('total downloaded: ' + torrent.downloaded);
console.log('download speed: ' + torrent.downloadSpeed);
console.log('progress: ' + torrent.progress);
});
torrent.on('done', function () {
console.log('done...');
});
}
}

最佳答案

Electron 应用程序是在下载后关闭,还是继续运行? (如果是前者,您需要一种方法来延迟关闭,直到您确定写入已完成。例如,确保没有 Unresolved promise 。)

done 消息是否发生在并非所有内容都写入磁盘的情况下?

您需要将两个错误处理程序添加到您的代码中,它们可能会解释问题。

客户有an error handler .

torrent 对象也有 an error handler .

关于javascript - 为什么我完成的种子(有时)没有写入磁盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59481593/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com