Right click -> "Save torrent file" without using streams

For #233
This commit is contained in:
Feross Aboukhadijeh
2016-03-27 01:06:58 -07:00
parent e88ad66e48
commit ecfe243b16

View File

@@ -871,13 +871,12 @@ function saveTorrentFileAs (torrentSummary) {
filters: [{ name: 'Torrents', extensions: ['torrent'] }] filters: [{ name: 'Torrents', extensions: ['torrent'] }]
} }
dialog.showSaveDialog(remote.getCurrentWindow(), opts, (savePath) => { dialog.showSaveDialog(remote.getCurrentWindow(), opts, (savePath) => {
var torrentFile = fs.createReadStream(torrentSummary.torrentPath) fs.readFile(torrentSummary.torrentPath, function (err, torrentFile) {
var savedTorrentFile = fs.createWriteStream(savePath) if (err) return onError(err)
torrentFile.on('error', (err) => console.error('Error reading torrent file', err)) fs.writeFile(savePath, torrentFile, function (err) {
savedTorrentFile.on('error', (err) => console.error('Error saving torrent file', err)) if (err) return onError(err)
savedTorrentFile.on('close', () => console.log('Torrent saved', savePath)) })
})
torrentFile.pipe(savedTorrentFile)
}) })
} }