encode object didn't support binary(buffer) as obj key
bittorrent scrape need to use infohash as key, it is a binary.
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.
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/
the key of
piece layersdict 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