简体   繁体   English

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

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

I try to write a little torrent client with electron and webtorrent.我尝试用电子和 webtorrent 编写一个小洪流客户端。 Everything seems fine at first but sometimes when a torrent is finished downloading the resulting files are not getting written to disk.一开始一切似乎都很好,但有时当 torrent 下载完成时,结果文件没有写入磁盘。

My project is setup via the SimulatedGREG/electron-vue boilerplate.我的项目是通过 SimulatedGREG/electron-vue 样板设置的。

Here the code of my torrent client class:这是我的 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...');
    });
  }
}

Does the Electron app shut down after the download, or does it keep running?下载后 Electron 应用程序是关闭还是继续运行? (If the former, you'll need a way to delay that shutdown until you are sure writing has completed. Eg Make sure there are no unresolved promises.) (如果是前者,您将需要一种方法来延迟关闭,直到您确定写入已完成。例如,确保没有未解决的承诺。)

Does the done message happen in the case when not everything is written to disk?在并非所有内容都写入磁盘的情况下,是否会发生done消息?

There are two error handlers you need to add to your code, which are likely to explain the problem.您需要将两个错误处理程序添加到您的代码中,它们很可能可以解释问题。

The client has an error handler .客户端有一个错误处理程序

The torrent object also has an error handler . torrent 对象也有一个错误处理程序

Update: I fixed the problem.更新:我解决了这个问题。

After I debugged the fs-chunk-store which webtorrent is using, I found out that an error is thrown right before the data is writen to disk.在我调试了 webtorrent 正在使用的 fs-chunk-store 之后,我发现在数据写入磁盘之前抛出了一个错误。 The error occures when fs.mkdir is called to create the new path for the download destination ( ENOENT: no such file or directory, mkdir 'path/to/folder').当调用 fs.mkdir 为下载目的地创建新路径时发生错误(ENOENT:没有这样的文件或目录,mkdir 'path/to/folder')。 Without a callback function as parameter the error will not be printed to stdout.如果没有回调函数作为参数,错误将不会打印到标准输出。

My solution now is to use a custom implementation of fs-chunk-store which allows the creation of folders recursivly.我现在的解决方案是使用 fs-chunk-store 的自定义实现,它允许递归创建文件夹。

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

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