From 4a791bd7000aaec632f7c17a6ebe2f212e154596 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 8 Mar 2017 10:08:41 +0000 Subject: [PATCH 1/2] chore: add node_modules to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules From 744583ce2251d7b51c3254f415e35e5941442703 Mon Sep 17 00:00:00 2001 From: David Dias Date: Wed, 8 Mar 2017 10:09:03 +0000 Subject: [PATCH 2/2] wip --- index.js | 12 +++++++----- test/encode.js | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index d9ca910..1f88cd3 100644 --- a/index.js +++ b/index.js @@ -107,11 +107,13 @@ function encodeTorrentFile (parsed) { info: parsed.info } - torrent['announce-list'] = (parsed.announce || []).map(function (url) { - if (!torrent.announce) torrent.announce = url - url = new Buffer(url, 'utf8') - return [ url ] - }) + if (parsed.announce.length > 0) { + torrent['announce-list'] = (parsed.announce || []).map(function (url) { + if (!torrent.announce) torrent.announce = url + url = new Buffer(url, 'utf8') + return [ url ] + }) + } torrent['url-list'] = parsed.urlList || [] diff --git a/test/encode.js b/test/encode.js index 7b9362d..c819998 100644 --- a/test/encode.js +++ b/test/encode.js @@ -4,9 +4,12 @@ var test = require('tape') test('encode', function (t) { var parsedTorrent = parseTorrentFile(fixtures.leaves.torrent) + var buf = parseTorrentFile.encode(parsedTorrent) var doubleParsedTorrent = parseTorrentFile(buf) + console.log(buf.length, fixtures.leaves.torrent.length) + t.deepEqual(buf, fixtures.leaves.torrent) t.deepEqual(doubleParsedTorrent, parsedTorrent) t.end() })