Code: Select all
buf:=FileRead("*c test.torrent")
size:=VarSetCapacity(buf)
;3 kinds of use:
f:=[]
f.push(bto("test.torrent"))
f.push(bto(buf))
f.push(bto(&buf,size))
MsgBox % ObjTree(f)
![Image](https://oi44.photobucket.com/albums/f1/imgahk/Mobile%20Uploads/20170424094954_zpstimdvssc.jpg)
Code: Select all
bto(byref file,size:=""){
type(file)="Integer"
?ad:=file
:isbyref(file) and (size:=strlen(file)/2)>259
?ad:=&file
:(buf:=FileRead("*c " file),size:=strlen(buf)/2,ad:=&buf)
,tree:=[],key:=[],len:=0,list:={(f:=first:=[]):1},hex:=bintohex(ad+0,size),hexs:=size*2
,en:=RegExMatch(StrGet(ad,520,"utf-8"),"iU)8:encoding\d:(.*)\d:",s)?s.1:"utf-8"
while len<hexs
{
if instr("idle1234567890",(str:="",s:=chr("0x" substr(hex,len+1,2))))
gosub,% s+1?"s":s
else
Return first.err:=len " " StrGet(ad+len/2-18,36,"utf-8"),first
}
Return first.Length()=1?first.1:first
w:
(list[f]?f.push(str):key[f]?(f[key[f]]:=str,key.delete(f)):key[f]:=str)
Return
e:
f:=tree[f],len+=2
Return
l:
j:=f,f:=[],len+=2,tree[f]:=j,list[f]:=1,list[j]?j.push(f):key[j]?(j[key[j]]:=f,key.delete(j)):key[j]:=f
Return
r:
while (r:=chr("0x" substr(hex,len+1+a_index*2,2))+0)!=""
str.=r
len+=strlen(str)*2+4
Return
i:
gosub,r
gosub,w
Return
d:
j:=f,f:=[],len+=2,tree[f]:=j,list[j]?j.push(f):key[j]?(j[key[j]]:=f,key.delete(j)):key[j]:=f
Return
s:
gosub,r
b:=substr(hex,len+1,d:=(sz:= s str)*2),str:=sz>5000?b:(hextobin(h,b),m:=StrGet(&h,sz,en),instr(m,"�")?b:m),len+=d
gosub,w
Return
}