繁体   English   中英

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

[英]Why are my finished torrents (sometimes) not getting written to disk?

我尝试用电子和 webtorrent 编写一个小洪流客户端。 一开始一切似乎都很好,但有时当 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 应用程序是关闭还是继续运行? (如果是前者,您将需要一种方法来延迟关闭,直到您确定写入已完成。例如,确保没有未解决的承诺。)

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

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

客户端有一个错误处理程序

torrent 对象也有一个错误处理程序

更新:我解决了这个问题。

在我调试了 webtorrent 正在使用的 fs-chunk-store 之后,我发现在数据写入磁盘之前抛出了一个错误。 当调用 fs.mkdir 为下载目的地创建新路径时发生错误(ENOENT:没有这样的文件或目录,mkdir 'path/to/folder')。 如果没有回调函数作为参数,错误将不会打印到标准输出。

我现在的解决方案是使用 fs-chunk-store 的自定义实现,它允许递归创建文件夹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM