func (mi *MetaInfo) ReadFromFile(filename string) error { b, err := ioutil.ReadFile(filename) if err != nil { return err } mi.raw = b dec := bencode.NewDecoder(b) o, err := dec.Decode() if err != nil { return errors.New("Couldn't parse torrent: " + err.Error()) } mi.parsed = o.(map[string]interface{}) return nil }
func test0r(in string) { fmt.Printf("testoring: '%s' ...\n", in) p := bencode.NewDecoder([]byte(in)) for !p.Consumed { l, err := p.Decode() if err != nil { fmt.Printf("\tparser error: %v\n", err) break } switch l.(type) { case []interface{}: x := l.([]interface{}) fmt.Printf("\tlist:\n") for _, o := range x { fmt.Printf("\t\tobj(%s): %#v\n", reflect.TypeOf(o).Name(), o) } fmt.Printf("\tlist_end\n") default: fmt.Printf("\tobj(%s): %#v\n", reflect.TypeOf(l).Name(), l) } } }