From b1e28a04a500642a1d55e3d6624d754e0dbe6f27 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 11 Jun 2014 17:56:20 -0700 Subject: [PATCH] bncode -> bencode --- index.js | 12 ++++++------ package.json | 2 +- test/basic.js | 4 ++-- test/fetch.js | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 5d25fea..9c2e6da 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ var BitField = require('bitfield') -var bncode = require('bncode') +var bencode = require('bencode') var EventEmitter = require('events').EventEmitter var inherits = require('inherits') var Rusha = require('rusha-browserify') // Fast SHA1 (works in browser) @@ -64,7 +64,7 @@ module.exports = function (metadata) { try { var str = buf.toString() var trailerIndex = str.indexOf('ee') + 2 - dict = bncode.decode(str.substring(0, trailerIndex)) + dict = bencode.decode(str.substring(0, trailerIndex)) trailer = buf.slice(trailerIndex) } catch (err) { // drop invalid messages @@ -117,9 +117,9 @@ module.exports = function (metadata) { // if full torrent dictionary was passed in, pull out just `info` key try { - var info = bncode.decode(metadata).info + var info = bencode.decode(metadata).info if (info) { - metadata = bncode.encode(info) + metadata = bencode.encode(info) } } catch (err) {} @@ -135,13 +135,13 @@ module.exports = function (metadata) { this._metadataSize = this.metadata.length this._wire.extendedHandshake.metadata_size = this._metadataSize - this.emit('metadata', bncode.encode({ info: bncode.decode(this.metadata) })) + this.emit('metadata', bencode.encode({ info: bencode.decode(this.metadata) })) return true } ut_metadata.prototype._send = function (dict, trailer) { - var buf = bncode.encode(dict) + var buf = bencode.encode(dict) if (Buffer.isBuffer(trailer)) { buf = Buffer.concat([buf, trailer]) } diff --git a/package.json b/package.json index d2f167b..ecfef72 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "url": "https://github.com/feross/ut_metadata/issues" }, "dependencies": { + "bencode": "^0.6.0", "bitfield": "^1.0.1", - "bncode": "^0.5.0", "inherits": "^2.0.1", "rusha-browserify": "^0.7.3" }, diff --git a/test/basic.js b/test/basic.js index 174f96b..5307829 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,7 +1,7 @@ var fs = require('fs') var Protocol = require('bittorrent-protocol') var ut_metadata = require('../') -var bncode = require('bncode') +var bencode = require('bencode') var test = require('tape') // Used in multiple tests @@ -29,6 +29,6 @@ test('wire.use(ut_metadata(metadata))', function (t) { t.ok(wire.ut_metadata) t.ok(wire.ut_metadata.fetch) t.ok(wire.ut_metadata.cancel) - t.equal(wire.ut_metadata.metadata.toString('hex'), bncode.encode(bncode.decode(metadata).info).toString('hex')) + t.equal(wire.ut_metadata.metadata.toString('hex'), bencode.encode(bencode.decode(metadata).info).toString('hex')) t.end() }) diff --git a/test/fetch.js b/test/fetch.js index 9f20947..17e860a 100644 --- a/test/fetch.js +++ b/test/fetch.js @@ -2,7 +2,7 @@ var fs = require('fs') var parseTorrent = require('parse-torrent') var Protocol = require('bittorrent-protocol') var ut_metadata = require('../') -var bncode = require('bncode') +var bencode = require('bencode') var test = require('tape') // Used in multiple tests @@ -29,7 +29,7 @@ test('fetch()', function (t) { wire2.ut_metadata.on('metadata', function (_metadata) { // got metadata! - t.equal(_metadata.toString('hex'), bncode.encode({ info: bncode.decode(metadata).info }).toString('hex')) + t.equal(_metadata.toString('hex'), bencode.encode({ info: bencode.decode(metadata).info }).toString('hex')) }) wire2.on('handshake', function (infoHash, peerId, extensions) { @@ -114,7 +114,7 @@ test('fetch when peer gets metadata later (setMetadata)', function (t) { wire2.ut_metadata.on('metadata', function (_metadata) { // got metadata! - t.equal(_metadata.toString('hex'), bncode.encode({ info: bncode.decode(metadata).info }).toString('hex')) + t.equal(_metadata.toString('hex'), bencode.encode({ info: bencode.decode(metadata).info }).toString('hex')) }) wire2.on('handshake', function (infoHash, peerId, extensions) { @@ -153,7 +153,7 @@ test('fetch() large torrent', function (t) { wire2.ut_metadata.on('metadata', function (_metadata) { // got metadata! - t.equal(_metadata.toString('hex'), bncode.encode({ info: bncode.decode(largeMetadata).info }).toString('hex')) + t.equal(_metadata.toString('hex'), bencode.encode({ info: bencode.decode(largeMetadata).info }).toString('hex')) }) wire2.on('handshake', function (infoHash, peerId, extensions) {