From 6c9d48c5da6fb94d10cbb206eb445349eeacb065 Mon Sep 17 00:00:00 2001 From: ftrees <58193105+ftreesmilo@users.noreply.github.com> Date: Mon, 9 Dec 2019 19:46:51 -0500 Subject: [PATCH 1/3] allow for progress on write --- lib/torrent.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/torrent.js b/lib/torrent.js index 77cf8988..0cb9eb5b 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -113,6 +113,8 @@ class Torrent extends EventEmitter { // for cleanup this._servers = [] this._xsRequests = [] + + this._writeCb = opts.writeCb, // TODO: remove this and expose a hook instead // optimization: don't recheck every file if it hasn't changed @@ -1597,7 +1599,11 @@ class Torrent extends EventEmitter { if (!cb) cb = noop const readable = new MultiStream(streams) + let read = 0; const writable = new ChunkStoreWriteStream(this.store, this.pieceLength) + if (this._writeCb) { + writable._blockstream.on('data', data => this._writeCb(this.length, read += data.length)) + } pump(readable, writable, err => { if (err) return cb(err) From 818b01501d01dcc677f1ae610b601a4c8a87932a Mon Sep 17 00:00:00 2001 From: ftrees <58193105+ftreesmilo@users.noreply.github.com> Date: Mon, 9 Dec 2019 20:13:18 -0500 Subject: [PATCH 2/3] fix bot issues --- lib/torrent.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/torrent.js b/lib/torrent.js index 0cb9eb5b..a146aab7 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -114,7 +114,7 @@ class Torrent extends EventEmitter { this._servers = [] this._xsRequests = [] - this._writeCb = opts.writeCb, + this._writeCb = opts.writeCb // TODO: remove this and expose a hook instead // optimization: don't recheck every file if it hasn't changed @@ -1602,7 +1602,10 @@ class Torrent extends EventEmitter { let read = 0; const writable = new ChunkStoreWriteStream(this.store, this.pieceLength) if (this._writeCb) { - writable._blockstream.on('data', data => this._writeCb(this.length, read += data.length)) + writable._blockstream.on('data', data => { + read += data.length + this._writeCb(this.length, read) + }) } pump(readable, writable, err => { From e90dfaabe1dd499fd31d2a58b17bef0d6af9725d Mon Sep 17 00:00:00 2001 From: ftrees <58193105+ftreesmilo@users.noreply.github.com> Date: Mon, 9 Dec 2019 22:11:30 -0500 Subject: [PATCH 3/3] more bot appeasements --- lib/torrent.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/torrent.js b/lib/torrent.js index a146aab7..203d5f57 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -113,7 +113,7 @@ class Torrent extends EventEmitter { // for cleanup this._servers = [] this._xsRequests = [] - + this._writeCb = opts.writeCb // TODO: remove this and expose a hook instead @@ -1599,7 +1599,7 @@ class Torrent extends EventEmitter { if (!cb) cb = noop const readable = new MultiStream(streams) - let read = 0; + let read = 0 const writable = new ChunkStoreWriteStream(this.store, this.pieceLength) if (this._writeCb) { writable._blockstream.on('data', data => {