diff options
author | Anthony MOI <anthony@totems.co> | 2015-01-08 19:33:11 +0300 |
---|---|---|
committer | Anthony MOI <anthony@totems.co> | 2015-01-08 19:33:11 +0300 |
commit | f3b84a6bc5fa72b67a62f91033bd3baf68cb4fda (patch) | |
tree | 4d4681d7b420c965faf71a5eab5b8b0c9075d02e | |
parent | 5c3227d3f12e7ea649f8e0cdb4b23d3a4e7f08c5 (diff) |
fix Piece.verify method and update README with options available when adding a torrent
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | lib/storage.js | 4 |
2 files changed, 13 insertions, 3 deletions
@@ -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. diff --git a/lib/storage.js b/lib/storage.js index cfaa825..4a3588e 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -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() } } |