Skip to content
This repository has been archived by the owner on Apr 13, 2018. It is now read-only.

Commit

Permalink
Support UTF-8 torrents
Browse files Browse the repository at this point in the history
support 'name.utf-8' and 'path.utf-8' keys
  • Loading branch information
feross committed Jul 1, 2015
1 parent 11b76d7 commit 47e48fc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ function decodeTorrentFile (torrent) {

// sanity check
ensure(torrent.info, 'info')
ensure(torrent.info.name, 'info.name')
ensure(torrent.info['name.utf-8'] || torrent.info.name, 'info.name')
ensure(torrent.info['piece length'], 'info[\'piece length\']')
ensure(torrent.info.pieces, 'info.pieces')

if (torrent.info.files) {
torrent.info.files.forEach(function (file) {
ensure(typeof file.length === 'number', 'info.files[0].length')
ensure(file.path, 'info.files[0].path')
ensure(file['path.utf-8'] || file.path, 'info.files[0].path')
})
} else {
ensure(typeof torrent.info.length === 'number', 'info.length')
Expand All @@ -37,7 +37,7 @@ function decodeTorrentFile (torrent) {
result.infoBuffer = bencode.encode(torrent.info)
result.infoHash = sha1.sync(result.infoBuffer)

result.name = torrent.info.name.toString()
result.name = (torrent.info['name.utf-8'] || torrent.info.name).toString()
result.private = !!torrent.info.private

if (torrent['creation date']) result.created = new Date(torrent['creation date'] * 1000)
Expand Down Expand Up @@ -69,9 +69,9 @@ function decodeTorrentFile (torrent) {
return url.toString()
})

var files = torrent.info.files || [torrent.info]
var files = torrent.info.files || [ torrent.info ]
result.files = files.map(function (file, i) {
var parts = [].concat(file.name || result.name, file.path || []).map(function (p) {
var parts = [].concat(result.name, file['path.utf-8'] || file.path || []).map(function (p) {
return p.toString()
})
return {
Expand Down

0 comments on commit 47e48fc

Please sign in to comment.