簡體   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