为什么我完成的种子(有时)没有写入磁盘?
Why are my finished torrents (sometimes) not getting written to disk?
我尝试用 electron 和 webtorrent 写一个小的 torrent 客户端。一开始一切似乎都很好,但有时当 torrent 下载完成时,生成的文件没有写入磁盘。
我的项目是通过 SimulatedGREG/electron-vue 样板设置的。
这是我的 torrent 客户端的代码 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...');
});
}
}
Electron 应用程序是在下载后关闭,还是保持 运行? (如果是前者,您需要一种方法来延迟关闭,直到您确定写入已完成。例如,确保没有未解决的承诺。)
done
消息是否在未将所有内容写入磁盘的情况下发生?
您需要将两个错误处理程序添加到您的代码中,它们可能会解释问题。
客户有an error handler.
种子文件还有an error handler.
更新:我解决了这个问题。
调试webtorrent使用的fs-chunk-store后,发现数据写入磁盘前报错。当调用 fs.mkdir 为下载目标创建新路径时发生错误(ENOENT:没有这样的文件或目录,mkdir 'path/to/folder')。如果没有回调函数作为参数,错误将不会打印到标准输出。
我现在的解决方案是使用 fs-chunk-store 的自定义实现,它允许递归地创建文件夹。
我尝试用 electron 和 webtorrent 写一个小的 torrent 客户端。一开始一切似乎都很好,但有时当 torrent 下载完成时,生成的文件没有写入磁盘。
我的项目是通过 SimulatedGREG/electron-vue 样板设置的。
这是我的 torrent 客户端的代码 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...');
});
}
}
Electron 应用程序是在下载后关闭,还是保持 运行? (如果是前者,您需要一种方法来延迟关闭,直到您确定写入已完成。例如,确保没有未解决的承诺。)
done
消息是否在未将所有内容写入磁盘的情况下发生?
您需要将两个错误处理程序添加到您的代码中,它们可能会解释问题。
客户有an error handler.
种子文件还有an error handler.
更新:我解决了这个问题。
调试webtorrent使用的fs-chunk-store后,发现数据写入磁盘前报错。当调用 fs.mkdir 为下载目标创建新路径时发生错误(ENOENT:没有这样的文件或目录,mkdir 'path/to/folder')。如果没有回调函数作为参数,错误将不会打印到标准输出。
我现在的解决方案是使用 fs-chunk-store 的自定义实现,它允许递归地创建文件夹。