2017年1月2日星期一

javascript读取种子文件信息

B编码

https://github.com/benjreinhart/bencode-js

Usage

CommonJS environments:
Bencode = require('bencode-js')
Bencode.decode(...)
Bencode.encode(...)
In the browser the object is available globally as window.Bencode.

Bencode#encode(object)

object is either a StringNumberArray, or Object.
Bencode.encode("string")         // => "6:string"
Bencode.encode(123)              // => "i123e"
Bencode.encode(["str", 123])     // => "l3:stri123ee"
Bencode.encode({ key: "value" }) // => "d3:key5:valuee"

Bencode#decode(string)

string is a Bencoded string.
Bencode.decode("d3:key5:valuee") // => { key: "value" }