![](/img/trans.png)
[英]Sometimes data is not getting written in the AWS S3 bucket by Lambda
[英]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...');
});
}
}
更新:我解決了這個問題。
在我調試了 webtorrent 正在使用的 fs-chunk-store 之后,我發現在數據寫入磁盤之前拋出了一個錯誤。 當調用 fs.mkdir 為下載目的地創建新路徑時發生錯誤(ENOENT:沒有這樣的文件或目錄,mkdir 'path/to/folder')。 如果沒有回調函數作為參數,錯誤將不會打印到標准輸出。
我現在的解決方案是使用 fs-chunk-store 的自定義實現,它允許遞歸創建文件夾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.