Fix bug in Webtorrent

This commit is contained in:
Mitra Ardron 2018-04-27 11:52:27 +10:00
parent 30077716a3
commit b34f47c3c1

View File

@ -236,7 +236,7 @@ class TransportWEBTORRENT extends Transport {
*/ */
if (verbose) console.log("TransportWEBTORRENT p_f_createreadstream %o", url); if (verbose) console.log("TransportWEBTORRENT p_f_createreadstream %o", url);
try { try {
let filet = this._p_fileTorrentFromUrl(url); let filet = await this._p_fileTorrentFromUrl(url);
let self = this; let self = this;
if (wanturl) { if (wanturl) {
console.log("XXX@WT:242 returning",url) console.log("XXX@WT:242 returning",url)
@ -260,14 +260,16 @@ class TransportWEBTORRENT extends Transport {
:returns stream: The readable stream. :returns stream: The readable stream.
*/ */
if (verbose) console.log("TransportWEBTORRENT createreadstream %o %o", file.name, opts); if (verbose) console.log("TransportWEBTORRENT createreadstream %o %o", file.name, opts);
let through;
try { try {
const through = new stream.PassThrough(); through = new stream.PassThrough();
const fileStream = file.createReadStream(opts); const fileStream = file.createReadStream(opts);
fileStream.pipe(through); fileStream.pipe(through);
return through; return through;
} catch(err) { } catch(err) {
console.log("TransportWEBTORRENT caught error", err) console.log("TransportWEBTORRENT caught error", err)
if (typeof through.destroy === 'function') through.destroy(err) if (typeof through.destroy === 'function')
through.destroy(err)
else through.emit('error', err) else through.emit('error', err)
} }
} }