javascriptnode.jselectronwebtorrent

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


I try to write a little torrent client with electron and webtorrent. Everything seems fine at first but sometimes when a torrent is finished downloading the resulting files are not getting written to disk.

My project is setup via the SimulatedGREG/electron-vue boilerplate.

Here the code of my torrent client class:

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...');
    });
  }
}

Solution

  • 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. 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'). 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.