aardio 文档

aardio 范例: bencode 编码解码

//bencode 编码解码
import crypt;
import bencode.magnet;
import inet.http;
import bencode;

//下载 torrent
var torrentBin = inet.http.get("https://webtorrent.io/torrents/big-buck-bunny.torrent")

//bencode 解码
var torrentInfo,rest = bencode.decode(torrentBin);
print( torrentInfo["info"]["name"]);

//bencode 编码
var bin = bencode.encode(torrentInfo);

//bencode 编码并保存到文件
bencode.save("/big-buck-bunny.torrent",torrentInfo);

//自文件解码
var torrentInfo = bencode.load("/big-buck-bunny.torrent")

//编码元数据
var metadata = bencode.encode( torrentInfo.info )

//元数据哈希
var hash = crypt.sha1(metadata,true)
print("magnet:?xt=urn:btih:" + hash);

//生成磁力链接
//参数可指定 torrent 数据、*.torrent,*.aria2 文件路径
var magnet = bencode.magnet.get("/big-buck-bunny.torrent")
print(magnet)


Markdown 格式