From 2b60a6bde68bc541222cb8e4da5efdf72acf01d9 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 7 May 2014 12:09:39 -0700 Subject: [PATCH] simplify metadata done check --- index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index f84c686..40c27a4 100644 --- a/index.js +++ b/index.js @@ -176,20 +176,19 @@ module.exports = function (metadata) { } if (!done) return - // check hash - var info try { - info = bncode.encode(bncode.decode(this.metadata)) - } catch (err) { // if buffer fails to decode, then data was corrupt + bncode.decode(this.metadata) + } catch (err) { return this._failedMetadata() } - if (info && sha1(info) === this._infoHash.toString('hex')) { - this._gotMetadata(bncode.encode({ info : bncode.decode(this.metadata) })) + + // check hash + if (sha1(this.metadata) === this._infoHash.toString('hex')) { + this._gotMetadata(bncode.encode({ info: bncode.decode(this.metadata) })) } else { this._failedMetadata() } - } ut_metadata.prototype._gotMetadata = function (_metadata) {