webtorrent / node-bencode

bencode de/encoder for nodejs
MIT License
166 stars 36 forks source link

Error: not a number: buffer[42910] = 18 #95

Closed caryyu closed 3 years ago

caryyu commented 3 years ago

Reference: https://github.com/caryyu/bteye/blob/bencode-experiment/test/bencode.test.js

Exception

/Users/caryyu/Desktop/bteye/node_modules/bencode/lib/decode.js:44
    throw new Error('not a number: buffer[' + i + '] = ' + num)
    ^

Error: not a number: buffer[42910] = 18
    at getIntFromBuffer (/Users/caryyu/Desktop/bteye/node_modules/bencode/lib/decode.js:44:11)
    at Function.decode.buffer (/Users/caryyu/Desktop/bteye/node_modules/bencode/lib/decode.js:160:16)
    at Function.decode.dictionary (/Users/caryyu/Desktop/bteye/node_modules/bencode/lib/decode.js:127:17)
    at Function.decode.next (/Users/caryyu/Desktop/bteye/node_modules/bencode/lib/decode.js:94:21)
    at Function.decode.dictionary (/Users/caryyu/Desktop/bteye/node_modules/bencode/lib/decode.js:127:36)
    at Function.decode.next (/Users/caryyu/Desktop/bteye/node_modules/bencode/lib/decode.js:94:21)
    at Object.decode (/Users/caryyu/Desktop/bteye/node_modules/bencode/lib/decode.js:83:17)
    at Request._callback (/Users/caryyu/Desktop/bteye/test/bencode.test.js:10:24)
    at Request.self.callback (/Users/caryyu/Desktop/bteye/node_modules/request/request.js:185:22)
    at Request.emit (events.js:314:20)

Reproduce

Git-check out the referred the repo above, and then execute the following commands

npm i
node test/bencode.test.js
jhermsmeier commented 3 years ago

That particular torrent file parses fine for me with bencode – I think you might need to set request's option encoding: null to receive the response body as a Buffer instead of whatever it's defaulting to, as that might be mangling your response body.

caryyu commented 3 years ago

@jhermsmeier It worked, thanks a lot