diff options
author | Feross Aboukhadijeh <feross@feross.org> | 2017-03-14 00:11:45 +0300 |
---|---|---|
committer | Feross Aboukhadijeh <feross@feross.org> | 2017-03-14 00:11:45 +0300 |
commit | 9c3de0e38b0add7411e466a3e3f8529a8a778c56 (patch) | |
tree | 23b9473b47f48a50d1a2d7c24c78de2f61548c92 /lib | |
parent | d60762cab91244d1bc23ab8b6a7f1a3a7726b164 (diff) |
Fix files under 16Kb are not downloaded correctly
Fixes: https://github.com/feross/webtorrent/issues/1077
Bug originally introduced in:
https://github.com/feross/webtorrent/commit/6ef2785e4bbed07f2429725ed2b0
5bd91fc36233?diff=split
Diffstat (limited to 'lib')
-rw-r--r-- | lib/torrent.js | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/lib/torrent.js b/lib/torrent.js index d09395f..9617b18 100644 --- a/lib/torrent.js +++ b/lib/torrent.js @@ -1131,10 +1131,7 @@ Torrent.prototype._updateSelections = function () { Torrent.prototype._gcSelections = function () { var self = this - var i - var toRemove = [] - - for (i = 0; i < self._selections.length; ++i) { + for (var i = 0; i < self._selections.length; ++i) { var s = self._selections[i] var oldOffset = s.offset @@ -1147,16 +1144,9 @@ Torrent.prototype._gcSelections = function () { if (s.to !== s.from + s.offset) continue if (!self.bitfield.get(s.from + s.offset)) continue - // remove fully downloaded selection - toRemove.push(i) - } + self._selections.splice(i, 1) // remove fully downloaded selection + i -= 1 // decrement i to offset splice - if (toRemove.length > 0) { - // Since self._selections is being modified in-place, it's necessary to - // traverse `toRemove` in reverse. - for (i = toRemove.length - 1; i >= 0; --i) { - self._selections.splice(i, 1) - } s.notify() self._updateInterest() } |