Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode object didn't support binary(buffer) as obj key #88

Open
fisherwei opened this issue May 7, 2020 · 3 comments
Open

encode object didn't support binary(buffer) as obj key #88

fisherwei opened this issue May 7, 2020 · 3 comments

Comments

@fisherwei
Copy link

bittorrent scrape need to use infohash as key, it is a binary.

@themasch
Copy link
Sponsor Contributor

themasch commented May 7, 2020

Yeah we kind of where working on that in ~2014 but never really made any good progress that does not break the interface or destroy performance for all other cases.
While I see non-utf8/ascii keys beeing a thing in the wild, you are just the second user asking for that feature and the spec reads "Keys must be strings ..."

That beeing said, if I'm wrong about the spec, or if we find a way to support this without reducing useability for other users I'll be happy to help getting this implemented.

@Chocobo1
Copy link

With bittorrent v2 format going popular, I'm starting to see byte strings being used as obj keys. For example, the key of piece layers dict is a merkle tree root which is a byte string.

https://www.bittorrent.org/beps/bep_0052.html

You can find example torrents in v2 format in this blog post: https://blog.libtorrent.org/2020/09/bittorrent-v2/

@milahu
Copy link

milahu commented Aug 30, 2023

the key of piece layers dict is a merkle tree root which is a byte string.

in my case

import fs from 'fs'
import bencode from 'bencode'

var buffer = fs.readFileSync("input-v2-only.torrent")

var object = bencode.decode(buffer)
var objectUtf8 = bencode.decode(buffer, 'utf8')
var objectAscii = bencode.decode(buffer, 'ascii')

console.log(Object.keys(object['piece layers'])[0])
console.log(Object.keys(objectUtf8['piece layers'])[0])
console.log(Object.keys(objectAscii['piece layers'])[0])

gives

26a161137a3fcfa67b79c239fd0e27e68b63f0b6ca373ddf1730b4aa69d14bbf
undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined09undefinedundefinedundefinedundefinedundefinedundefinedundefined07undefinedundefinedundefined00undefinedundefinedundefinedundefinedundefinedundefined
undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined09undefinedundefinedundefinedundefinedundefinedundefinedundefined07undefinedundefinedundefined00undefinedundefinedundefinedundefinedundefinedundefined

which looks like a bug with encoding utf8 and ascii

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants