From f3b84a6bc5fa72b67a62f91033bd3baf68cb4fda Mon Sep 17 00:00:00 2001 From: Anthony MOI Date: Thu, 8 Jan 2015 17:33:11 +0100 Subject: [PATCH] fix Piece.verify method and update README with options available when adding a torrent --- README.md | 12 ++++++++++-- lib/storage.js | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a701b7e..d717c1ea 100644 --- a/README.md +++ b/README.md @@ -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 cfaa8254..4a3588e9 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() } }