diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules 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() })