/
filelist.go
45 lines (38 loc) · 967 Bytes
/
filelist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package filelist
import (
"compress/bzip2"
"encoding/xml"
"io"
"github.com/direct-connect/go-dc/adc/types"
"github.com/direct-connect/go-dc/tiger"
)
type Dir struct {
Name string `xml:"Name,attr"`
Incomplete int `xml:"Incomplete,attr"`
Dirs []Dir `xml:"Directory"`
Files []File `xml:"File"`
}
type File struct {
Name string `xml:"Name,attr"`
Size int64 `xml:"Size,attr"`
TTH tiger.Hash `xml:"TTH,attr"`
}
type FileList struct {
Version int `xml:"Version,attr"`
CID types.CID `xml:"CID,attr"`
Base string `xml:"Base,attr"`
Generator string `xml:"Generator,attr"`
Dirs []Dir `xml:"Directory"`
Files []File `xml:"File"`
}
func Decode(r io.Reader) (*FileList, error) {
var list FileList
err := xml.NewDecoder(r).Decode(&list)
if err != nil {
return nil, err
}
return &list, nil
}
func DecodeBZIP(r io.Reader) (*FileList, error) {
return Decode(bzip2.NewReader(r))
}