Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better download control #1285

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

fix style errors

  • Loading branch information
vintikzzz committed Mar 11, 2018
commit 0db55b75b8ad65885cd12f24d92377f17c8209af
@@ -37,13 +37,13 @@ function FileStream (file, opts) {
this._reading = false
this._notifying = false
this._criticalLength = Math.min((1024 * 1024 / pieceLength) | 0, 2)
this._backPreasure = false;
this._backPreasure = false
}

FileStream.prototype._read = function () {
if (this._reading) return
this._reading = true
this.emit('piece', this._piece);
this.emit('piece', this._piece)
}

FileStream.prototype._notify = function () {
@@ -79,7 +79,7 @@ FileStream.prototype._notify = function () {
debug('pushing buffer of length %s', buffer.length)
self._reading = false
var backPressure = self.push(buffer)
if (!backPressure && self._missing !== 0) self.emit('piece', self._piece);
if (!backPressure && self._missing !== 0) self.emit('piece', self._piece)
if (self._missing === 0) self.push(null)
})
self._piece += 1
@@ -82,11 +82,11 @@ File.prototype.createReadStream = function (opts) {

var pieceLength = this._torrent.pieceLength

var selectLength = Math.min((5 * 1024 * 1024 / pieceLength) | 0, 2);
var selectLength = Math.min((5 * 1024 * 1024 / pieceLength) | 0, 2)

var fileStream = new FileStream(self, opts)
function select (start) {
if (start > fileStream._endPiece) return;
if (start > fileStream._endPiece) return
var end = (start + selectLength < fileStream._endPiece)
? start + selectLength
: fileStream._endPiece
@@ -96,8 +96,8 @@ File.prototype.createReadStream = function (opts) {
})
}
fileStream.on('piece', function (p) {
select(p);
});
select(p)
})
select(fileStream._startPiece)

eos(fileStream, function () {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.