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

fix Piece.verify method and update README #240

Merged
merged 1 commit into from Jan 9, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -247,8 +247,7 @@ If `opts` is specified, then the default options (shown below) will be overridde
peerId: String|Buffer, // Wire protocol peer ID (default=randomly generated)
rtcConfig: Object, // RTCPeerConnection configuration object (default=STUN only)
storage: Function // custom storage engine, or `false` to use in-memory engine
tracker: Boolean, // Whether or not to enable trackers (default=true)
verify: Boolean // Verify previously stored data before starting (default=false)
tracker: Boolean // Whether or not to enable trackers (default=true)
}
```

@@ -265,6 +264,15 @@ Start downloading a new torrent. Aliased as `client.download`.
- http/https url to a torrent file (string)
- filesystem path to a torrent file (string)

If `opts` is specified, then the default options (shown below) will be overridden.

```js
{
tmp: String, // Custom folder where files will be downloaded (default=`/tmp/`)
verify: Boolean // Verify previously stored data before starting (default=false)
}
```

If `ontorrent` is specified, then it will be called when **this** torrent is ready to be
used (i.e. metadata is available). Note: this is distinct from the 'torrent' event which
will fire for **all** torrents.
@@ -132,12 +132,14 @@ Piece.prototype.verify = function (buffer) {
return
}

var expected_hash
if (self.noVerify) {
self.verified = true
onResult()
} else {
sha1(buffer, function (hash) {
self.verified = (hash === self.hash)
expected_hash = hash
onResult()
})
}
@@ -146,7 +148,7 @@ Piece.prototype.verify = function (buffer) {
if (self.verified) {
self.emit('done')
} else {
self.emit('warning', new Error('piece ' + self.index + ' failed verification; ' + sha1(buffer) + ' expected ' + self.hash))
self.emit('warning', new Error('piece ' + self.index + ' failed verification; ' + expected_hash + ' expected ' + self.hash))
self._reset()
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.